public enum TimeOfDay{
Morning = 0,
Afternoon = 1,
Evening = 2
}
class EnumExample{
public Static int Main(){
WriteGreeting(TimeOfDay.Morning);
return 0;
}
static void WriteGreeting(TimeOfDay timeOfDay){
switch(timeOfDay){
case TimeOfDay.Morning:
Console.WriteLine("Good morning!");
break;
case TimeOfDay.Afternoon:
Console.WriteLine("Good afternoon!");
break;
case TimeOfDay.Evening:
Console.WriteLine("Good evening!");
break;
default:
Console.WriteLine("Hello!");
break;
}
}
}
TimeOfDay time = TimeOfDay.Afternoon;
Console.WriteLine(time.ToString());
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者