Unnecessary code rules
Unnecessary code rules identify different parts of the code base that are unnecessary and can be refactored or removed. The presence of unnecessary code indicates one of more of the following problems:
- Readability: Code that is unnecessarily degrading readability. For example, IDE0001 flags unnecessary type-name qualifications.
- Maintainability: Code that is no longer used after refactoring and is unnecessarily being maintained. For example, IDE0051 flags unused private fields, properties, events, and methods.
- Performance: Unnecessary computation that has no side effects and leads to unnecessary performance overhead. For example, IDE0059 flags unused value assignments where the expression to compute a value has no side effects.
- Functionality: Functional issue in code leading to required code being rendered redundant. For example, IDE0060 flags unused parameters where the method accidentally ignores an input parameter.
The rules in this section concern the following unnecessary code rules:
- Simplify name (IDE0001)
- Simplify member access (IDE0002)
- Remove unnecessary cast (IDE0004)
- Remove unnecessary import (IDE0005)
- Remove unreachable code (IDE0035)
- Remove unused private member (IDE0051)
- Remove unread private member (IDE0052)
- Remove unused expression value (IDE0058)
- Remove unnecessary value assignment (IDE0059)
- Remove unused parameter (IDE0060)
- Remove unnecessary suppression (IDE0079)
- Remove unnecessary suppression operator (IDE0080) - C# only.
- Remove 'ByVal' (IDE0081) - Visual Basic only.
- Remove unnecessary equality operator (IDE0100)
- Remove unnecessary discard (IDE0110) - C# only.
Some of these rules have options to configure the rule behavior:
- csharp_style_unused_value_expression_statement_preference (IDE0058)
- visual_basic_style_unused_value_expression_statement_preference (IDE0058)
- csharp_style_unused_value_assignment_preference (IDE0059)
- visual_basic_style_unused_value_assignment_preference (IDE0059)
- dotnet_code_quality_unused_parameters (IDE0060)
- dotnet_remove_unnecessary_suppression_exclusions (IDE0079)