找不到类型或命名空间名称“TimeOfDay”(是否缺少 using 指令或程序集引用?)
using System;namespace Worx.CSharp.Basics
{
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;
}
}
}
}
这段代码是c#高级编程第四版中的一个例子,编译时TimeOfDay下有一道绿线,不知道要怎么写才能不出错。