object Enum.Parse(System.Type enumType, string value, bool ignoreCase)
Define Enum:
enum Weekday
{
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
}Weekday wd = null;string weekDay = "Monday";
First check is it enum that you are going to convert exists or not, otherwise it will
return an exception:
if (Enum.IsDefined(typeof(Weekday), weekDay))
wd = (WeekDay) Enum.Parse(typeof(Weekday), weekDay, true);
else
Response.Write("Enum does'not exist.");
No comments:
Post a Comment