public enum EGameDev
{
Why,
Does,
It,
Not,
Work
}
public EGameDev ThePeople = (EGameDev)"Work";
.. but it doesn't work. [depressed]
[.net] (Enum)string
I thought you could do this in C#...
I think you have to use reflection in order to do that. It does work with integers, but you'll have to initialize the first value to 0 to be sure you'll be able to cast.
It does work on switch statements however:
Toolmaker
It does work on switch statements however:
switch (str){ case "case a": break; case "case b": break;}
Toolmaker
The syntax your looking for is
System.Enum.Parse(typeof(Enum Type Name), str);
Its possible you could write a type converter/overloaded operator that would let you use that (EnumTypeName)"string" syntax but I'm not really into operator overloading so I can't advise you on that.
System.Enum.Parse(typeof(Enum Type Name), str);
Its possible you could write a type converter/overloaded operator that would let you use that (EnumTypeName)"string" syntax but I'm not really into operator overloading so I can't advise you on that.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement