Skip to main content

CRR0042 - Unused parameter

  • 2 minutes to read

Unused parameter detects parameters that are not used in methods. Specify accessibility levels for these methods in the CodeRush options dialog:

  • Open the Editor | C# (Visual Basic) | Code Analysis | Unused Code Analysis options page.

  • Specify accessibility levels for methods with unused parameters. For example, check internal (Friend) and public options, and uncheck other options to allow this analyzer to detect unused parameters in internal and public methods.

    RemoveQualifier

The following example demonstrates how the analyzer detects unused parameters in internal and public methods:

RemoveQualifier

Tip

Use the Highlight unused code in editor check box in the Editor | C# (Visual Basic) | Code Analysis | General option page to enable or disable the highlighting of unused parameters in methods for the code editor.

To fix the issues, perform one of the following actions in the code:

  • Remove the unused parameter or use it in the method:
class Project {
    public void SomeMethod1(int a) {
        Calculate(a);
    }

    private string SomeMethod2(string param1, int param2) {
        return String.Format("the param2 value is {0}", param2);
    }

    internal int Calculate(int a) {
        return a * a;
    }
}

To remove unused parameters in private methods at once, customize the Remove unused parameters cleanup rule as shown in the screenshot below. This allows CodeRush to apply this cleanup rule when you save a document and when you run code cleanup.

EnableCleanup

Run Code Cleanup.

Limitations

The analyzer ignores:

  • Virtual, override methods and interface implementations.

  • The “this” parameter of extension methods.

  • Methods that have attributes defined on them.

  • Empty or unsupported methods.