Get int value from enum in C#

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

    Declare it as a static class having public constants:

    public static class Question
    {
        public const int Role = 2;
        public const int ProjectFunding = 3;
        public const int TotalEmployee = 4;
        public const int NumberOfServers = 5;
        public const int TopBusinessConcern = 6;
    }
    

    And then you can reference it as Question.Role, and it always evaluates to an int or whatever you define it as.

提交回复
热议问题