> JE> This fails at compile-time: > JE> > JE> public enum MyEnum : short { > JE> ValueOne = 0, > JE> ValueTwo = 1, > JE> } > JE> > JE> Console.WriteLine((MyEnum)Int32.MaxValue); > >What is exactly your point, here? C#'s short type is mapped to >System.Int16. Surely 2^32 - 1 exeeds the range of an enumerated >type that's backed up by a 16-bit integer. > > short n = (short) System.Int32.MaxValue; > >fails just as well.
My point was that this fails at compile-time: public enum MyEnum : short { ValueOne = 0, ValueTwo = 1, } Console.WriteLine((MyEnum)Int32.MaxValue); The point was to communicate a fact. I didn't say anything about expecting otherwise. In retrospect all truth seems to be stating the obvious. This comment seemed relevant to the question at hand, namely why a cast to an enum didn't fail at compile time. If you didn't know that you could specify the base types for your enums this would be useful information. It's also nice to know that the compiler will fail it at compile-time, which I wouldn't say was immediately obvious or necessarily something that you'd just assume. John. =================================== This list is hosted by DevelopMentorŪ http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com