A string array of the names of the constants in enumType.
Type Reason ArgumentNullException enumType is a null reference. ArgumentException enumType is not a Type that describes a Enum .
The elements of the return value array are sorted by the binary values of the enumerated constants (that is, by their unsigned magnitude). The following example provides displays information about the array returned by the Enum.GetNames(Type) method for an enumeration that includes a negative, zero, and positive value.
code reference: System.Enum.GetNames#1
If there are enumerated constants with same value, the order of their corresponding names is unspecified.
The following example demonstrates the Enum.GetNames(Type) method.
C# Example
using System; public enum Colors { Red, White, Blue }; public class enumGetNames { public static void Main() { int i = 0; String[] strAry = Colors.GetNames( typeof(Colors) ); foreach (String str in strAry) { Console.Write("The value indexed '{0}' ", i++ ); Console.WriteLine("is {0}.", str); } } }
The output is
The value indexed '0' is Red.