Try this minimal code:
void Main()
{
Foo test;
test = 0;
test = 1;
Console.WriteLine(test);
}
enum Foo { Bar, Baz }
The line test = 1
will throw a compilation error, however the line test = 0
is happily compiled!
CS0266 Cannot implicitly convert type 'int' to 'UserQuery.Foo'. An explicit conversion exists (are you missing a cast?)
Compiler version: Microsoft (R) Visual C# Compiler version 1.0.0.50618
Why can I only assign a value of zero? Shouldn't it be a missing cast error in either case?