Disclaimer. I don't condone this kind of enum. It leads to confusion and is error prone. Still, I'm curious about the irregularity I've discovered.
I was plying with the following code (fiddle here):
enum Anims{
Donkey = 1, Wonkey = 1,
Monkey = 2, Oinky =2,
A = 3, B = 3, C = 3, bb = 4, aa = 4
}
foreach(Anims anim in Enum.GetValues(typeof(Anims)))
Console.WriteLine((Anims)((int)anim));
The result I expected was either that the values declared first would be presented. Possibly the values that were assigned last. None of that happened. I was also considering an alphabetical order in the output. Nope...
What is the algorithm deciding what an integer will be cast into in an enum if there are multiple values corresponding to it?
Output:
Wonkey
Wonkey
Monkey
Monkey
A
A
A
bb
bb