Compiler Error CS0178

无效的秩说明符:应为“,”或“]”

数组初始化的格式错误。例如,在指定数组维数时,可以指定以下内容:

  • 中括号中的数字。

  • 空的中括号。

  • 括在中括号中的逗号。

有关更多信息,请参见 数组(C# 编程指南) 和 C# 规范 (C# 语言规范) 中有关数组初始值设定项的部分。

下面的示例生成 CS0178。

// CS0178.cs
class MyClass
{
   public static void Main()
   {
      int a = new int[5][,][][5;   // CS0178
      int[,] b = new int[3,2];   // OK

      int[][] c = new int[10][];
      c[0] = new int[5][5];   // CS0178
      c[0] = new int[2];   // OK
      c[1] = new int[2]{1,2};   // OK
   }
}