συμβάν
17 Μαρ, 9 μ.μ. - 21 Μαρ, 10 π.μ.
Συμμετάσχετε στη σειρά meetup για να δημιουργήσετε κλιμακούμενες λύσεις AI που βασίζονται σε πραγματικές περιπτώσεις χρήσης με συναδέλφους προγραμματιστές και ειδικούς.
Εγγραφή τώραΑυτό το πρόγραμμα περιήγησης δεν υποστηρίζεται πλέον.
Κάντε αναβάθμιση σε Microsoft Edge για να επωφεληθείτε από τις τελευταίες δυνατότητες, τις ενημερώσεις ασφαλείας και την τεχνική υποστήριξη.
Property | Value |
---|---|
Rule ID | IDE0051 |
Title | Remove unused private member |
Category | CodeQuality |
Subcategory | Unnecessary code rules (expression-level preferences) |
Applicable languages | C# and Visual Basic |
This rule flags unused private methods, fields, properties, and events that have no read or write references.
This rule has no associated code-style options.
// Code with violations
class C
{
// IDE0051: Remove unused private members
private readonly int _fieldPrivate;
private int PropertyPrivate => 1;
private int GetNumPrivate() => 1;
// No IDE0051
internal readonly int FieldInternal;
private readonly int _fieldPrivateUsed;
public int PropertyPublic => _fieldPrivateUsed;
private int GetNumPrivateUsed() => 1;
internal int GetNumInternal() => GetNumPrivateUsed();
public int GetNumPublic() => GetNumPrivateUsed();
}
// Fixed code
class C
{
// No IDE0051
internal readonly int FieldInternal;
private readonly int _fieldPrivateUsed;
public int PropertyPublic => _fieldPrivateUsed;
private int GetNumPrivateUsed() => 1;
internal int GetNumInternal() => GetNumPrivateUsed();
public int GetNumPublic() => GetNumPrivateUsed();
}
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 IDE0051
// The code that's violating the rule is on this line.
#pragma warning restore IDE0051
To disable the rule for a file, folder, or project, set its severity to none
in the configuration file.
[*.{cs,vb}]
dotnet_diagnostic.IDE0051.severity = none
To disable this entire category of rules, set the severity for the category to none
in the configuration file.
[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-CodeQuality.severity = none
For more information, see How to suppress code analysis warnings.
.NET σχόλια
.NET είναι ένα έργο ανοιχτού κώδικα. Επιλέξτε μια σύνδεση για να παρέχετε σχόλια:
συμβάν
17 Μαρ, 9 μ.μ. - 21 Μαρ, 10 π.μ.
Συμμετάσχετε στη σειρά meetup για να δημιουργήσετε κλιμακούμενες λύσεις AI που βασίζονται σε πραγματικές περιπτώσεις χρήσης με συναδέλφους προγραμματιστές και ειδικούς.
Εγγραφή τώρα