public enum class Color {Black, White, Red}; public enum class TransactionType : unsigned char {Deposit, Withdrawal, Transfer}; int main() { Color c = Color::White;
/*1*/ Console::WriteLine("Color::Red's name is >{0}<", Enum::GetName(c.GetType(), Color::Red)); Console::Write("Color's members are:");
/*2*/ array<String^>^ names = Enum::GetNames(Type::GetType("Color")); for each (String^ s in names) { Console::Write(" {0}", s); } Console::WriteLine();
/*3*/ Console::WriteLine("The type underlying Color is >{0}<", Enum::GetUnderlyingType(Color::typeid));
/*4*/ Console::WriteLine("The type underlying TransactionType is >{0}<", Enum::GetUnderlyingType(TransactionType::typeid)); } 插2:例7的输出
Color::Red's name is >Red< Color's members are: Black White Red The type underlying Color is >System.Int32< The type underlying TransactionType is >System.Byte< 在标号1中,调用了Enum::GetName以找出特定enum类型枚举器的名称,第一个参数必须为System::Type类型,而获取它的一个方法就是通过对感爱好的变量调用Object::GetType。