Stupid Compiler Question or Compiler Stupid Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am confused why I must cast an enum to a type int if I defined the enum as follows:

enum COLUMNS :int
{
IP=0,
MSG =1
}

IMHO the compiler should be able to make the conversion without requiring a cast. I am curious why the cast is required.

Bill
 
Bill said:
I am confused why I must cast an enum to a type int if I defined the
enum as follows:

enum COLUMNS :int
{
IP=0,
MSG =1
}

IMHO the compiler should be able to make the conversion without
requiring a cast. I am curious why the cast is required.

It's required for type-safety - it's to show the compiler that you know
it really *isn't* just an int. I'm all for it, myself.
 
Obviously, I don't understand the purpose of the :type syntax on an enum. Please point me to where I can get a better grasp of it’s purpose.
 
Bill said:
Obviously, I don't understand the purpose of the :type syntax on an
enum. Please point me to where I can get a better grasp of it?s
purpose.

The purpose of the : type syntax is effectively to say how it should be
implemented - what size it should use internally. That doesn't mean
that there is an implicit conversion between the enum and that type,
fortunately. See section 21 of the C# ECMA spec.
 
Back
Top