Get an array of the values of the constants in a specified enum in CSharp
Description
The following code shows how to get an array of the values of the constants in a specified enum.
Example
using System;//from w w w. jav a 2 s. co m
enum SignMagnitude { Negative = -1, Zero = 0, Positive = 1 };
public class Example
{
public static void Main()
{
foreach (var value in Enum.GetValues(typeof(SignMagnitude))) {
Console.WriteLine("{0,3} 0x{0:X8} {1}",
(int) value, ((SignMagnitude) value));
}
}
}
The code above generates the following result.