11

If short is just the C# syntax for using the Int16 struct, and you can interchange each like this:

Int16 x = 10;
//or
short x = 10;

then why can you do this:

public enum DaysOfWeek : short
{

}

but not this:

public enum DaysOfWeek : Int16
{

}

The error is Type byte, sbyte, short, ushort, int, uint, long or ulong expected.

David Klempfner
  • 8,700
  • 20
  • 73
  • 153
  • 4
    The enum grammar doesn't call for a type, it calls for one of a fixed set of keywords. – Ben Voigt Feb 17 '14 at 04:57
  • 1
    The best answer to this is here: http://stackoverflow.com/questions/3774650/enum-members-of-int32-type – Petr Abdulin Feb 17 '14 at 05:00
  • From http://reinventingthewheel.azurewebsites.net/DotNetFacts.aspx: "The reason for this is because Int32 is not a keyword, you could create your own class called Int32, but the enum would not be allowed to derive from this since it wouldn't be an integral type." – David Klempfner Aug 11 '17 at 00:51

0 Answers0