Quick question about enums
I was wondering...
enum Size : int
{
SIZE_SMALL = 0,
SIZE_MEDIUM = 1,
SIZE_BIG = 2
}
int myInt = 1;
string myString = "SIZE_SMALL";
Is there anyway I can access members in the enum "Size" using my 2 variables? (By value or by name)?
I don't want to just get the name, or get the value, I want a reference to that particular constant.
BrianPosted Jan 3, 2006, 3:26 PM
Mike GoldPosted Jan 3, 2006, 3:22 PM
Check the code shown below. s1 shows you how to get the constant from a string. s2 shows you how to get the constant from an integer:
private void ShowEnum()
{
Size s1 = (Size)Enum.Parse(typeof(Size), "SIZE_SMALL", true);
Size s2 = (Size)myInt;
Console.WriteLine("s1={0}", s1);
Console.WriteLine("s2={0}", s2);
}