C# Error CS1104 – A parameter array cannot be used with ‘this’ modifier on an extension method

C# Error

CS1104 – A parameter array cannot be used with ‘this’ modifier on an extension method

Reason for the Error & Solution

A parameter array cannot be used with ‘this’ modifier on an extension method.

The first parameter of an extension method cannot be a params array.

To correct this error

  1. Remember that the first parameter of an extension method definition specifies which type the method will "extend". It is not an input parameter. Therefore, it makes no sense to have a params array in this location. If you do have to pass in a params array, make it the second parameter.

Example

The following example generates CS1104:

// cs1104.cs  
// Compile with: /target:library  
public static class Extensions  
{  
    public static void Test<T>(this params T[] tArr) {} // CS1104  
}

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