C# Error CS1737 – Optional parameters must appear after all required parameters

C# Error

CS1737 – Optional parameters must appear after all required parameters

Reason for the Error & Solution

Optional parameters must appear after all required parameters

The compiler does not support optional parameters being declared before required parameters. All optional parameters must be after all required parameters.

Example

The following sample generates CS1737:

// CS1737.cs (7,45)
class C
{
    static void F(object? x)
    {
        G(y: x);
    }
    static void G(object? x = null, object y)
    {
    }
}

To correct this error

The signature for this method may be changed without effecting existing code that calls the method because a value for the optional parameter has not been used. For example:

// CS1737.cs (7,45)
class C
{
    static void F(object? x)
    {
        G(y: x);
    }
    static void G(object y, object? x = null)
    {
    }
}

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