【发布时间】:2014-02-25 08:51:55
【问题描述】:
每当我声明 enum 时,它根本无法编译。我的代码如下所示:
private enum race {HUMAN, ORC, GOBLIN, UNDEAD}
// The name of the player
string playerName;
// The Health Points of the player. Is to be modified a LOT. Keep that in mind!
int HP = 100;
// Made to test if the name chosen i the right one
bool nameIsRight = false;
cout("Hello fair traveler!\n\n");
cout("It has come to my knowledge, that you, a puny warrior, is up for the challenge, that is killing the dragon\n\n");
cout("Our records seems to be damaged. What was your name again?\n\n");
cout("Enter your name: ");
// Sets playerName equal to the line entered by the player, turned into a string to prevent errors
playerName = Console.ReadLine().ToString();
cout("\n");
do
{
string test;
cout("Are you sure that is the right name? (y/n)\n");
test = Console.ReadLine();
cout("\n");
if (test.ToLower() == "y")
{
nameIsRight = true;
}
else if (test.ToLower() == "n")
{
cout("What is your name then?\n");
playerName = Console.ReadLine();
}
cout("\n");
} while (nameIsRight == false);
cout("So, your name is " + playerName + "? That is a name i haven't heard in a long time!\n\n");
cout("Just for the record, we need your race. Hope you don't mind telling it again.\n\n");
cout("1: Human\n\n2: ");
错误 1 } 预期 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 12 10 simpleRPGConsole
错误 2 方法必须具有返回类型 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 25 13 simpleRPGConsole
错误 3 类型预期 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 25 18 simpleRPGConsole
错误 4 方法必须具有返回类型 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 26 13 simpleRPGConsole
错误 5 类型预期 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 26 18 simpleRPGConsole
错误 6 方法必须具有返回类型 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 28 13 simpleRPGConsole
错误 7 类型应为 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 28 18 simpleRPGConsole
错误 8 方法必须具有返回类型 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 29 13 simpleRPGConsole
错误 9 类型应为 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 29 18 simpleRPGConsole
错误 10 类、结构或接口成员声明 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 32 24 simpleRPGConsole 中的标记“=”无效
错误 11 类、结构或接口成员声明 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 32 42 simpleRPGConsole 中的标记“(”无效
错误 12 方法必须具有返回类型 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 32 45 simpleRPGConsole
错误 13 方法必须具有返回类型 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 34 13 simpleRPGConsole
错误 14 类型应为 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 34 18 simpleRPGConsole
错误 15 方法必须具有返回类型 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 39 17 simpleRPGConsole
错误 16 类型应为 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 39 22 simpleRPGConsole
错误 17 类、结构或接口成员声明 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 40 22 simpleRPGConsole 中的标记“=”无效
错误 18 Invalid token '(' in class, struct, or interface member declaration C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 40 40 simpleRPGConsole
错误 19 方法必须具有返回类型 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 41 17 simpleRPGConsole
错误 20 类型应为 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 41 22 simpleRPGConsole
Error 21 Invalid token '(' in class, struct, or interface member declaration C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 42 33 simpleRPGConsole
错误 22 类、结构或接口成员声明 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 44 33 simpleRPGConsole 中的标记“=”无效
错误 23 命名空间不能直接包含字段或方法等成员 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 46 17 simpleRPGConsole
错误 24 命名空间不能直接包含字段或方法等成员 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 52 15 simpleRPGConsole
错误 25 类型或命名空间定义,或预期文件结尾 C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 57 9 simpleRPGConsole
我应该做些什么来帮助这个?我不想在没有枚举的情况下做出这样的事情!
赫伯斯坦
【问题讨论】:
-
从错误消息看来,代码是直接写在一个类中的,检查你所有的执行代码是否都在方法内,并且所有的括号都关闭了..
标签: c# visual-studio-2012 enums