Get int value from enum in C#

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

    It's easier than you think - an enum is already an int. It just needs to be reminded:

    int y = (int)Question.Role;
    Console.WriteLine(y); // Prints 2
    

提交回复
热议问题