I have the next object:
private enum Operation
{
Power = 0x5E, // ^
Division = 0x2F, // /
Multiplication = 0x2A, // *
Subtraction = 0x2D, // -
Addition = 0x2B // +
}
When I want to convert it into a char[] in the next way:
private static char[] GetOperators()
{
List<char> ExistingOperators = new List<char>();
foreach (Operation enumOperator in Enum.GetValues(typeof(Operation)))
{
ExistingOperators.Add((char)enumOperator);
Console.WriteLine(enumOperator);
}
return ExistingOperators.ToArray<char>();
}
It writes on the console the values of the enums, but in sorted from small to big.
The above example outputs:
Multiplication
Addition
Subtraction
Divison
Power
What I want to achieve: (so the array is in the same order as the enum declaration)
char[] { '^', '/', '*', '*', '-', '*' };
Thanks in advance.
Source: http://msdn.microsoft.com/en-us/library/system.enum.getvalues.aspx