CA1823: Avoid unused private fields
Property | Value |
---|---|
Rule ID | CA1823 |
Title | Avoid unused private fields |
Category | Performance |
Fix is breaking or non-breaking | Non-breaking |
Enabled by default in .NET 8 | No |
Cause
This rule is reported when a private field exists in your code but is not used by any code path.
Rule description
Private fields were detected that do not appear to be accessed in the assembly.
How to fix violations
To fix a violation of this rule, remove the field or add code that uses it.
When to suppress warnings
It is safe to suppress a warning from this rule.
Suppress a warning
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
#pragma warning disable CA1823
// The code that's violating the rule is on this line.
#pragma warning restore CA1823
To disable the rule for a file, folder, or project, set its severity to none
in the configuration file.
[*.{cs,vb}]
dotnet_diagnostic.CA1823.severity = none
For more information, see How to suppress code analysis warnings.
Related rules
التعاون معنا على GitHub
يمكن العثور على مصدر هذا المحتوى على GitHub حيث يمكنك أيضاً إضافة مشاكل وطلبات سحب ومراجعتها. للحصول على معلومات إضافية، اطلع على دليل المساهم لدينا.