C# Error CS1740 – Named argument ‘{0}’ cannot be specified multiple times

C# Error

CS1740 – Named argument ‘{0}’ cannot be specified multiple times

Reason for the Error & Solution

Named argument cannot be specified multiple times

Example

The following sample generates CS1740:

The compiler does not support passing more than one value for a named argument.

// CS1740.cs (9,17)
class C
{
    static void M(params int[] x)
    {
    }
    static void Main()
    {
        M(x: 1, x: 2);
    }
}

To correct this error

Pick which value should be passed as the argument and remove the other:

        M(x: 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...