Get int value from enum in C#

前端 未结 28 1922
臣服心动
臣服心动 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:22

    Use:

    Question question = Question.Role;
    int value = question.GetHashCode();
    

    It will result in value == 2.

    This is only true if the enum fits inside an int.

提交回复
热议问题