Changing the underlying type of an enumeration to long [duplicate]
Possible Duplicate:
C# int, Int32 and enum's
C# allows you to set the underlying type of an enumeration to long. But, how would you explain the di开发者_如何学编程fference in behavior when you try to compile the following two statements:
public enum Colors : long
{
Blue = 512L,
Purple = 1024L
}
and
public enum Colors : System.Int64
{
Blue = 512L,
Purple = 1024L
}
The first one compiles oK (with : long), while the second (with : System.Int64) wont compile - you get an error: Type byte, sbyte, short, ushort, int, uint, long, or ulong expected Note: Obviously, I understand the error message. What has me baffled is that I thought that "long" is more or less an alias for "Int64"
It is a limitation of the C# compiler and support for this on Enum
will not be introduced. You will have to use long
. Alex Turner (a Program Manager for Visual Basic and C#) at MSFT:
Posted by Microsoft on 6/25/2010 at 8:53 AM Thanks for the suggestion for Visual Studio!
As you point out, we could enable support for saying Int16 instead of int here, but this would not provide any extra expressiveness to C# programs (and it's more characters to type!). We'd be unlikely to invest our resources to add this support to Enums.
精彩评论