gpt4 book ai didi

c# - "Primary Constructor Body Is Not Allowed"错误

转载 作者:行者123 更新时间:2023-11-30 19:09:05 31 4
gpt4 key购买 nike

我的代码中出现错误“不允许使用主构造函数主体”,而且似乎找不到修复它的方法。错误发生是因为我创建了一个新的公共(public)方法,我也尝试使用私有(private)和 protected 方法,但错误仍然存​​在。这里还有其他人问了同样的问题 question .这个人得到的答案让我相信它可能是 OS X 特有的。这是我的代码:

        string txt = WordBank ();

string[] words = Moduel.TextToArray("Text.txt");
string compWord = Moduel.Random (words);
Console.WriteLine ("I have chosen a random word, try to guess it one letter at a time");
}

public static void WordBank ();
{
string txt;

Console.WriteLine ("Would you like to " +
"(A) choose 4 letter words " +
"(B) choose 5 letter words " +
"(C) choose 6 letter words " +
"(E) choose 7 lette r words or more?" +
"(F) all words?");

string input = Console.ReadLine ();
if (input = "A")
txt = "4 Letter Words.txt";
else if (input = "B")
txt = "5 Letter Words.txt";
else if (input = "C")
txt = "6 Letter Words.txt";
else if (input = "E")
txt = "7 Letters or More.txt";
else if (input = "F")
txt = "All Words.txt";
else
{
Console.WriteLine("You haven't chosen a valid option, please try again");
Main();
}
return txt;
}
}

这是错误的图片。 Error Message.

最佳答案

错误在

public static void WordBank ();

只需从这一行中删除分号

public static void WordBank ()

并且您的函数返回了一个字符串值,因此将函数的定义更改为

public static string WordBank ()

关于c# - "Primary Constructor Body Is Not Allowed"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34389117/

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