Why is Enum string value inconsistent?

Viewed 112

I have a enum, with members that are same value, but when I tried to print them as strings, I expected to see it uses the first defined value, that is, for Buy and Bid it prints Buy, and for Sell and Ask it prints Sell, but the test shows it looks they are randomly chosen, as it is neither first nor last for all values. so why is this inconsistence?

Sample code:

using System;

public enum OrderType
{
    Buy,
    Bid = Buy,
    Sell,
    Ask = Sell
}

public class Program
{
    public static void Main()
    {
        Console.WriteLine("Hello World");
        OrderType o = OrderType.Buy;
        Console.WriteLine("{0}: {1}", (int)o, o);
        OrderType o2 = OrderType.Bid;
        Console.WriteLine("{0}: {1}", (int)o2, o2);
        OrderType o3 = OrderType.Sell;
        Console.WriteLine("{0}: {1}", (int)o3, o3);
        OrderType o4 = OrderType.Ask;
        Console.WriteLine("{0}: {1}", (int)o4, o4);
    }
}

Output:

Buy: 0 - Bid
Bid: 0 - Bid
Sell: 1 - Sell
Ask: 1 - Sell
1 Answers
Related