Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, May 14, 2010 3:25 AM
i got a integer and need to converter it to a Enum.
However, i only know which Enum i should use in runtime.
How can i converter it or cast it dynamically?
All replies (4)
Sunday, May 16, 2010 10:47 PM âś…Answered
object myEnumObject = Enum.ToObject(type, value);
Friday, May 14, 2010 3:56 AM
enumItems str = (enumItems)0;
where
public enum enumItems
{
a = 0,
b,
c
}
see the line 1 for conversion from int to enum beloe for conversion from enum to int
int k = (int)enumItems.a;
Manish Sati
Friday, May 14, 2010 4:07 AM
Hi,
From a string:
YourEnum foo = (YourEnum) Enum.Parse(typeof(yourEnum), yourString);
From an int:
YourEnum foo = (YourEnum)yourInt;
Friday, May 14, 2010 4:13 AM
The Enum is only known in runtime, so i can't just simply use (YourEnum)yourInt;