【发布时间】:2022-01-02 06:27:29
【问题描述】:
我正在编写我的第一个 C# 算法挑战,我遇到了一个问题。我已将类型标识符添加到我的所有变量中,但我仍然收到需要标识符的错误。当实际类型标识符存在时,我不确定如何解决这个问题。这是我的代码,这是错误日志。
public class ShortLongShort
{
public static string Solution(string a, string b)
{
string long = a;
string short = b;
if(a.Length < b.Length) {
short = a;
long = b;
}
return short+long+short;
}
}
src/Solution.cs(5,12): error CS1001: Identifier expected
src/Solution.cs(5,12): error CS1002: ; expected
src/Solution.cs(5,17): error CS1001: Identifier expected
src/Solution.cs(6,12): error CS1001: Identifier expected
src/Solution.cs(6,12): error CS1002: ; expected
src/Solution.cs(6,18): error CS1001: Identifier expected
src/Solution.cs(8,15): error CS1001: Identifier expected
src/Solution.cs(9,14): error CS1001: Identifier expected
src/Solution.cs(11,12): error CS1525: Invalid expression term 'short'
src/Solution.cs(11,18): error CS1525: Invalid expression term 'long'
src/Solution.cs(11,23): error CS1525: Invalid expression term 'short'
【问题讨论】:
-
longandshort是reserved words,不能用作标识符。尝试@long/@short(verbatim identifier) 或将它们重命名为longString/shortString。