【问题标题】:c# type identifier exists but I'm still getting an error that it's expected [closed]c#类型标识符存在,但我仍然收到预期的错误[关闭]
【发布时间】: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'

【问题讨论】:

标签: c# algorithm


【解决方案1】:

“long”和“short”都是类型的关键字(long 是 64 位整数,short 是 16 位整数)。将“long”和“short”变量的名称更改为其他名称,例如“longValue”和“shortValue”。

Read more here.

【讨论】:

    【解决方案2】:

    long 和 short 是类型,这些变量使用不同的名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多