Enum.Parse 方法 (Type, String)
将一个或多个枚举常数的名称或数字值的字符串表示转换成等效的枚举对象。
参数
enumType
枚举的 Type。
value
包含要转换的值或名称的字符串。
返回值
enumType 类型的对象,其值由 value 表示。
public enum Weekday
{
Sun,Mon,Tue,Wen,Thu,Fri,Sat
}
static void Main (string[] args)
{
Weekday wd3 = (Weekday)Weekday.Parse(typeof(Weekday), Console.ReadLine());
}
private static Weekday NextDay(Weekday day)
{
Weekday nextDay;
if (day == Weekday.Sat)
{
nextDay = Weekday.Sun;
}
else
{
nextDay = day + 1 ;
}
return nextDay;
}