Redaguoti

Bendrinti naudojant


Remove unused parameter (IDE0060)

Property Value
Rule ID IDE0060
Title Remove unused parameter
Category Style
Subcategory Unnecessary code rules (parameter preferences)
Applicable languages C# and Visual Basic
Options dotnet_code_quality_unused_parameters

Overview

This rule flags unused parameters.

This rule does not flag parameters that are named with the discard symbol _. In addition, the rule ignores parameters that are named with the discard symbol followed by an integer, for example, _1. This behavior reduces warning noise on parameters that are needed for signature requirements, for example, a method used as a delegate, a parameter with special attributes, or a parameter whose value is implicitly accessed at run time by a framework but is not referenced in code.

Options

The option value specifies if unused parameters should be flagged only for non-public methods or for both public and non-public methods.

For information about configuring options, see Option format.

dotnet_code_quality_unused_parameters

Property Value Description
Option name dotnet_code_quality_unused_parameters
Option values all Flag methods with any accessibility that contain unused parameters
non_public Flag only non-public methods that contain unused parameters
Default option value all
// dotnet_code_quality_unused_parameters = all
public int GetNum1(int unusedParam) { return 1; }
internal int GetNum2(int unusedParam) { return 1; }
private int GetNum3(int unusedParam) { return 1; }

// dotnet_code_quality_unused_parameters = non_public
internal int GetNum4(int unusedParam) { return 1; }
private int GetNum5(int unusedParam) { return 1; }
' dotnet_code_quality_unused_parameters = all
Public Function GetNum1(unused As Integer)
    Return 1
End Function

Friend Function GetNum2(unused As Integer)
    Return 1
End Function

Private Function GetNum3(unused As Integer)
    Return 1
End Function

' dotnet_code_quality_unused_parameters = non_public
Friend Function GetNum4(arg1 As Integer)
    Return 1
End Function

Private Function GetNum5(arg1 As Integer)
    Return 1
End Function

Suppress a warning

If you want to suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.

#pragma warning disable IDE0060
// The code that's violating the rule is on this line.
#pragma warning restore IDE0060

To disable the rule for a file, folder, or project, set its severity to none in the configuration file.

[*.{cs,vb}]
dotnet_diagnostic.IDE0060.severity = none

To disable all of the code-style rules, set the severity for the category Style to none in the configuration file.

[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-Style.severity = none

For more information, see How to suppress code analysis warnings.

See also