C# Compiler Error
CS0178 – Invalid rank specifier: expected ‘,’ or ‘]’
Reason for the Error
You will receive this error in your C# code when the Array initialization is ill-formed with-in your program.
For example, lets try to compile the below code snippet.
namespace DeveloperPubNamespace { class Program { static void Main(string[] args) { int[][] inputArray = new int[10][1]; } } }
The above code snippet will result with the error code CS0178 because the array inputArray declaration and initialization seems to be ill-formed.
Error CS0178 Invalid rank specifier: expected ‘,’ or ‘]’ ConsoleApp3 C:\Users\Senthil\source\repos\ConsoleApp3\ConsoleApp3\Program.cs 8 Active
Solution
To fix the error, ensure that the array initialization is correct and uses the right format when you initialize the 1-D, 2D or Multi-dimensional arrays in C#.
The error code CS0178 in the above program can be fixed by replacing the array initialization as shown below.
namespace DeveloperPubNamespace { class Program { static void Main(string[] args) { int[,] inputArray = new int[10, 1]; } } }