Compiler Error CS0178


Updated: July 20, 2015

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

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