How can I create an enum using numbers?

Posted by Jordan S on Stack Overflow See other posts from Stack Overflow or by Jordan S
Published on 2010-06-01T18:19:02Z Indexed on 2010/06/01 18:23 UTC
Read the original article Hit count: 168

Filed under:
|
|
|
|

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 display and set this value. If I were to create an enum like this...

 private enum GainValues {One, Two, Four, Eight}

and I made my gain variable of type GainValues then the drop-down list in the propertygrid would only show the available values for the gain variable. The problem is I want the gain values to read numerically an not as words. But I can not create an enum like this:

 private enum GainValues {1,2,4,8}

So is there another way of doing this? Perhaps creating a custom type?

© Stack Overflow or respective owner

Related posts about c#

Related posts about grid