How can I create an enum using numbers?

前端 未结 7 1386
野趣味
野趣味 2021-01-11 11:11

Is it possible to make an enum using just numbers in C#? In my program I have a variable, Gain, that can only be set to 1, 2, 4, and 8. I am using a propertygrid control to

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-11 11:53

    private enum GainValues { One = 1, Two = 2, Four = 4, Eight = 8 }
    

    should work.

    Update: OK, I think I misunderstood you there.

    Maybe you could use a KeyValuePair and then bind the name and the value to the Key and Value property respectively.

提交回复
热议问题