gpt4 book ai didi

c# - 每当我声明一个枚举时,它都不会编译

转载 作者:太空宇宙 更新时间:2023-11-03 18:31:18 24 4
gpt4 key购买 nike

每当我声明一个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: ");

Error 1 } expected C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 12 10 simpleRPGConsole

Error 2 Method must have a return type C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 25 13 simpleRPGConsole

Error 3 Type expected C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 25 18 simpleRPGConsole

Error 4 Method must have a return type C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 26 13 simpleRPGConsole

Error 5 Type expected C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 26 18 simpleRPGConsole

Error 6 Method must have a return type C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 28 13 simpleRPGConsole

Error 7 Type expected C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 28 18 simpleRPGConsole

Error 8 Method must have a return type C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 29 13 simpleRPGConsole

Error 9 Type expected C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 29 18 simpleRPGConsole

Error 10 Invalid token '=' in class, struct, or interface member declaration C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 32 24 simpleRPGConsole

Error 11 Invalid token '(' in class, struct, or interface member declaration C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 32 42 simpleRPGConsole

Error 12 Method must have a return type C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 32 45 simpleRPGConsole

Error 13 Method must have a return type C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 34 13 simpleRPGConsole

Error 14 Type expected C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 34 18 simpleRPGConsole

Error 15 Method must have a return type C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 39 17 simpleRPGConsole

Error 16 Type expected C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 39 22 simpleRPGConsole

Error 17 Invalid token '=' in class, struct, or interface member declaration C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 40 22 simpleRPGConsole

Error 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

Error 19 Method must have a return type C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 41 17 simpleRPGConsole

Error 20 Type expected 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

Error 22 Invalid token '=' in class, struct, or interface member declaration C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 44 33 simpleRPGConsole

Error 23 A namespace cannot directly contain members such as fields or methods C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 46 17 simpleRPGConsole

Error 24 A namespace cannot directly contain members such as fields or methods C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 52 15 simpleRPGConsole

Error 25 Type or namespace definition, or end-of-file expected C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 57 9 simpleRPGConsole

我应该怎么做才能帮助解决这个问题?我不想在没有枚举的情况下制作这样的东西!

赫布斯坦

最佳答案

您没有显示完整代码,但您的 enum 似乎位于函数的中间。不要那样做。

此外,您的方法需要位于 中。查看一些很好的示例。

此外,cout 在 C# 中不存在 - 那是 C++ 的东西,您没有在任何语言中正确使用它。 C# 使用 Console.WriteLine

namespace MyApp
{
// Every method (function) must be in a class
class MyProgram
{
// This is where code execution begins
static void Main()
{
Console.WriteLine("Hello, world!");

string playerName = GetPlayerName();
}

static string GetPlayerName()
{
Console.WriteLine("Some cliche narrative here. Name?");

return Console.ReadLine();
}

// We can also make nested class/struct/enum definitions that are
// "private" to the containing class.
private enum APrivateEnum { Foo, Bar }
}

enum Race { Human, Orc, Goblin, Undead }
}

关于c# - 每当我声明一个枚举时,它都不会编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22008983/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com