Consider the following code:
using System;
namespace Test
{
enum Foo
{
A = 1,
B = 1,
C = 1
}
public static class Program
{
public static void Main()
{
Console.WriteLine("{0}, {1}, {2}", Foo.A, Foo.B, Foo.C);
}
}
}
Knowing that enums are just integers under the hood, I expected it to be either A, A, A or C, C, C. But surprisingly, it prints out B, B, B! This behaviour appears to be consistent across .NET Framework, .NET Core 3.x and .NET 5.
Why does it choose B?