system.array

C# Iterating through an enum? (Indexing a System.Array)

久未见 提交于 2019-11-26 06:19:59
问题 I have the following code: // Obtain the string names of all the elements within myEnum String[] names = Enum.GetNames( typeof( myEnum ) ); // Obtain the values of all the elements within myEnum Array values = Enum.GetValues( typeof( myEnum ) ); // Print the names and values to file for ( int i = 0; i < names.Length; i++ ) { print( names[i], values[i] ); } However, I cannot index values. Is there an easier way to do this? Or have I missed something entirely! 回答1: Array values = Enum.GetValues