Are enumerated types stored as int in C #?

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
}
+5
source share
6 answers

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.

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.

+5
source

, enum int ., .

, :

enum Foo : short
{
    Bar,
    Baz
}

.

+5
+2

enum int, . , byte:

enum Days : byte {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri};

. http://msdn.microsoft.com/en-us/library/sbbt4032.aspx.

+2

, , char. , 0,1,2 ,

, ,

+1

, :

IL/runtime . :

a: b: c: ( //)

( int). enum ( ..) , .., , , , / ; .

SomeEnum foo = SomeEnum.WithValueOne;
int bar = 1;

IL ( , ).

, , - .ToString() ..

: ( object/etc), , ( .ToString() ..)

+1
source

All Articles