Shamim Hafiz Shamim Hafiz - 12 days ago 4
C Question

How to get the Enum Index value in C#

In C,

, internally equates to an integer. Therefore we can treat data types of
as integer also.

How to achieve the same with C#?


Simply cast it to an int, like below:

int eValue = (int)enumValue;

Here's another example that shows you how to set up their internal integer values:

public enum MyEnum
    MyValue1 = 1,
    MyValue2 = 2

(int)MyEnum.MyValue2 == 2; // True