C# Error CS0022 – Wrong number of indices inside [], expected ‘number’

C# Compiler Error Message

Wrong number of indices inside [], expected ‘number’

Reason for the Error

You will get the C# compiler error CS0022 when you specify the in-correct number of dimensions with-in the square brackets when assigning values to array in C#.

For example, the below code snippet will result with the error CS0022 Wrong number of indices inside []; expected 1

public class DeveloperPublish
{
    public static void Main()
    {
        int[] array = new int[10];
        array[0] = 17;    
        // Assigning to 2D- Arry results in the CS0022
        array[0, 1] = 2;   
    }
}
C# Error CS0022 - Wrong number of indices inside [], expected 'number'

Solution

Fix the error by providing the right dimensions for the array with-in square brackets.

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...