How can I create an enum using numbers?

前端 未结 7 1408
野趣味
野趣味 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条回答
  •  孤独总比滥情好
    2021-01-11 11:45

    Unfortunately, symbols in C# can contain numbers, but cannot start with numbers. So you're gonna have to use words.

    Alternatively, you could do Gain1, Gain2, etc.

    Or you could forgo an enum altogether and use constants and internal processing.

提交回复
热议问题