Skip to main content

Extension method cannot have a parameter array used with 'this' modifier

In This Article

CodeRush Classic shows the Extension method cannot have a parameter array used with ‘this’ modifier code issue if this modifier is used with a parameter array on an extension method.

#Fix

Remove the params keyword.

#Purpose

Highlights the extension method declaration statements, which would cause the A parameter array cannot be used with ‘this’ modifier on an extension method compilation error.

#Example

public static int Total(params this int[] intArray)
{
    int result = 0;
    foreach (int item in intArray)
        result += item;
    return result;
}

Fix:

public static int Total(this int[] intArray)
{
    int result = 0;
    foreach (int item in intArray)
        result += item;
    return result;
}