Normally you can parse enum in c# like:
And then you can parse and enum from a string like:
CodesEnum MyStatus = (CodesEnum) Enum.Parse( typeof(StatusEnum), "Delta", true );But if you want to do it really professionally then you can define a generic method like:
public static T ConvertToEnum<T>( string value )
{
return (T) Enum.Parse( typeof( T ), value, true );
}
And then you can parse and enum from a string like:
CodesEnum MyStatus = Util.ConvertToEnum<CodesEnum>("Delta");

No comments:
Post a Comment
Your comments are highly appreciated!