Get int value from enum in C#

前端 未结 28 2317
臣服心动
臣服心动 2020-11-22 04:58

I have a class called Questions (plural). In this class there is an enum called Question (singular) which looks like this.

public e         


        
28条回答
  •  执念已碎
    2020-11-22 05:33

    Example:

    public enum EmpNo
    {
        Raj = 1,
        Rahul,
        Priyanka
    }
    

    And in the code behind to get the enum value:

    int setempNo = (int)EmpNo.Raj; // This will give setempNo = 1
    

    or

    int setempNo = (int)EmpNo.Rahul; // This will give setempNo = 2
    

    Enums will increment by 1, and you can set the start value. If you don't set the start value it will be assigned as 0 initially.

提交回复
热议问题