Returns a zero-based, one-dimensional string array that contains the names of the constants of the specified enumeration type.
[Edit]
[System.Runtime.InteropServices.ComVisible(true)] public static string[] GetNames (Type enumType) |
|
Parameters
- enumType
- A Type that specifies the type of an enumeration.
[Edit]
Returns
A string vector of the names of the constants in
enumType. The elements of the vector
are sorted by the values of the enumerated constants. If multiple constants have the same value, the order in which their names appear in the vector, relative to each other, is unspecified.
[Edit]
Exceptions
Remarks
Example
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.
The value indexed '1' is White.
The value indexed '2' is Blue.
Requirements
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0