Course Content
C# Beyond Basics
C# Beyond Basics
Enumerators
Enum, also known as Enumerator, is a structure for grouping together some integral constants. The constants are basically of the type int
.
Following is the syntax for creating an enum:
index.cs
By default the first element of an enum has the value 0, the second element has a value 1
and so on.
For-example:
index.cs
We can access the values of these constants using the enumName.constantName
syntax.
For-example:
index.cs
Note that in the above example we explicitly need to convert the constant into an int
datatype since these constants are of type Days
by default, which means that the enum Days
is a new datatype which we created. Therefore, it can be stored into a variable of type Days
:
This is useful in places like switch statements.
For-example:
index.cs
We can also manually assign values to the enum constants. The unassigned constants take up incremented values of the previous elements:
index.cs
Everything was clear?
Course Content
C# Beyond Basics
C# Beyond Basics
Enumerators
Enum, also known as Enumerator, is a structure for grouping together some integral constants. The constants are basically of the type int
.
Following is the syntax for creating an enum:
index.cs
By default the first element of an enum has the value 0, the second element has a value 1
and so on.
For-example:
index.cs
We can access the values of these constants using the enumName.constantName
syntax.
For-example:
index.cs
Note that in the above example we explicitly need to convert the constant into an int
datatype since these constants are of type Days
by default, which means that the enum Days
is a new datatype which we created. Therefore, it can be stored into a variable of type Days
:
This is useful in places like switch statements.
For-example:
index.cs
We can also manually assign values to the enum constants. The unassigned constants take up incremented values of the previous elements:
index.cs
Everything was clear?