coderushforroslyn-400839-static-code-analysis-analyzers-library-crr0042-unused-parameter.md
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.
The following example demonstrates how the analyzer detects unused parameters in internal and public methods:
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:
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;
}
}
Class Project
Public Sub SomeMethod1(ByVal a As Integer)
Calculate(a)
End Sub
Private Function SomeMethod2(ByVal param1 As String, ByVal param2 As Integer) As String
Return String.Format("the param2 value is {0}", param2)
End Function
Friend Function Calculate(ByVal a As Integer) As Integer
Return a * a
End Function
End Class
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.
Run Code Cleanup.
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.
See Also