enum Color {
Red, // Assigned a value of 0
Green, // Assigned a value of 1
Blue, // Assigned a value of 2
Orange // Assigned a value of 3
}
枚举类型在编译器编译的时候,编译器自动将每种枚举转换成常量类型.如上所示的,编译器会将 Color 转换为如下形式:
struct Color : System.Enum {
public const Color Red = (Color) 0;
public const Color Green = (Color) 1;
public const Color Blue = (Color) 2;
public const Color Orange = (Color) 3;
}