Shamim Hafiz Shamim Hafiz - 1 year ago 107
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#?

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download