The requested page is not available for the requested platform. You are viewing the content for Default platform.

CRR0042 - Unused parameter

This analyzer detects a method parameter that is not used in the method body.

void SomeMethod1(int a, int b) // the "b" parameter is unused
{
    Calculate(a);
}

void SomeMethod2(int a) // the "a" value is unused
{
    a = 10;
    Calculate(a);
}

To fix issues, remove the unused parameter from methods:

void SomeMethod1(int a) 
{
    Calculate(a);
}

void SomeMethod2() 
{
    a = 10;
    Calculate(a);
}

Call the Remove Unused Parameter refactoring to remove an unused parameter from a method. If you need to do it in different places at once, use the Code Cleanup feature with Remove unused parameter rule enabled.

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.