C# Error CS1742 – An array access may not have a named argument specifier

C# Error

CS1742 – An array access may not have a named argument specifier

Reason for the Error & Solution

An array access may not have a named argument specifier

Example

The following sample generates CS1742:

// CS1742.cs (0,0)
public class B
{
    static void Main()
    {
        int[] arr = { };
        int s = arr[arr: 1];
    }
}

An array may not be declared with a named argument. This code generates CS1742 because using the name arr to refer to an argument when accessing the array is not syntactically correct.

To correct this error

Remove the use of named arguments when accessing an array to correct this error:

    static void Main()
    {
        int[] arr = { };
        int s = arr[1];
    }

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...