// Error! SalesManager is not in the EmpType enum!
EmpType emp = EmpType.SalesManager;
// Error! Forgot to scope Grunt value to EmpType enum!
emp= Grunt;
Console.ReadLine();
}
The System.Enum Type
The interesting thing about .NET enumerations is that they gain functionality from the System.Enum
class type. This class defines a number of methods that allow you to interrogate and transform a
given enumeration. One helpful method is the static Enum.GetUnderlyingType(), which as the name
implies returns the data type used to store the values of the enumerated type (System.Byte in the
case of the current EmpType declaration).
static void Main(string[] args)
{
Console.WriteLine("**** Fun with Enums *****");
// Make a contractor type.
EmpType emp = EmpType.Contractor;
AskForBonus(emp);
Do'stlaringiz bilan baham: |