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

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

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...