How do you make an 'enum' that has data tied to it?

前端 未结 6 1957
深忆病人
深忆病人 2021-01-23 02:28

I have a Vote class and one of the properties it can have is a vote type. Such as unanimous, a 3/4 vote, a simply majority, etc. Each type needs to have a string associated with

6条回答
  •  我在风中等你
    2021-01-23 03:05

    You could create a "constant" dictionary (or rather readonly static, since you can't create a constant dictionary) around your Enum.

    public enum VoteType { Unanimous = 1, SimpleMajority = 2, ... }
    
    public static readonly Dictionary VoteDescriptions = new Dictionary
    {
        { VoteType.Unanimous, "Unanimous description" },
        { VoteType.SimpleMajority, "Simple majority" },
        ...
    };
    

提交回复
热议问题