// Print storage for the enum.
Console.WriteLine("EmpType uses a {0} for storage",
Enum.GetUnderlyingType(emp.GetType()));
Console.ReadLine();
}
If you were to consult the Visual Studio 2008 object browser, you would be able to verify that
the Enum.GetUnderlyingType() method requires you to pass in a System.Type as the first parameter.
As fully examined in Chapter 16, Type represents the metadata description of a given .NET entity.
One possible way to obtain metadata (as shown previously) is to use the GetType() method,
which is common to all types in the .NET base class libraries. Another approach is to make use of
the C# typeof operator. One benefit of doing so is that you do not need to have a variable of the
entity you wish to obtain a metadata description of:
Do'stlaringiz bilan baham: |