G
Guest
I've read all the posts in this forum that I can find that look related to
this issue and I have only found 1 solution that I consider to be a bit of a
hack. What I want to do is assign a value to an enum variable using an int.
What I am using right now is something like this:
public enum MyEnum
{
value1,
value2,
value3
};
....
MyEnum var1;
// this value actually comes from a database so I can't substitute the
literal value
int intVar = 1;
var1 = (MyEnum)Enum.Parse(var1.GetType(), intVar.ToString());
Is there a simpler way to do this? It doesn't seem like setting the value
should require converting to string and then parsing and casting.
this issue and I have only found 1 solution that I consider to be a bit of a
hack. What I want to do is assign a value to an enum variable using an int.
What I am using right now is something like this:
public enum MyEnum
{
value1,
value2,
value3
};
....
MyEnum var1;
// this value actually comes from a database so I can't substitute the
literal value
int intVar = 1;
var1 = (MyEnum)Enum.Parse(var1.GetType(), intVar.ToString());
Is there a simpler way to do this? It doesn't seem like setting the value
should require converting to string and then parsing and casting.