Are there enum types stored as int in C #?
Will the listing below be represented as 0, 1, 2?
If not, what is the easiest way to define an enumeration?
public enum ColumnType { INT,STRING,OBJECT }
From MSDN
The default primary enumeration element type is int.By default, the first counter has a value of 0, and the value of each subsequent counter is incremented by 1.
The default primary enumeration element type is int.
By default, the first counter has a value of 0, and the value of each subsequent counter is incremented by 1.
So your assumptions are correct. Enumare saved as int, and your example will be presented as 0, 1, 2. However, you should not rely on this and always refer to them for their intended purpose if someone overrides the default value.
Enum
int
, enum int ., .
enum
, :
enum Foo : short { Bar, Baz }
.
:
http://msdn.microsoft.com/en-us/library/sbbt4032(v=vs.80).aspx
enum , , . , , char. - int. 0, 1.
enum int, . , byte:
byte
enum Days : byte {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri};
. http://msdn.microsoft.com/en-us/library/sbbt4032.aspx.
, , char. , 0,1,2 ,
, ,
IL/runtime . :
a: b: c: ( //)
( int). enum ( ..) , .., , , , / ; .
SomeEnum foo = SomeEnum.WithValueOne; int bar = 1;
IL ( , ).
, , - .ToString() ..
: ( object/etc), , ( .ToString() ..)
object