Compiler Error CS0178

Invalid rank specifier: expected ',' or ']'

An array initialization was ill-formed. For example, when specifying the array dimensions, you can specify the following:

  • A number in brackets

  • Empty brackets

  • A comma enclosed in brackets

For more information, see Arrays and the C# specification (C# Language Specification) section on array initializers.


The following sample generates 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