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
use explicit value assignment in the enum:
private enum GainValues
{
One = 1,
Two = 2,
Four = 4,
Eight = 8
}
Then to enumerate through these values do as follows:
GainValues currentVal;
foreach(currentVal in Enum.GetValues(typeof(GainValues))
{
// add to combo box (or whatever) here
}
Then you can cast to/from ints as necessary:
int valueFromDB = 4;
GainValues enumVal = (GainValues) valueFromDB;
// enumVal should be 'Four' now