diff --git a/docs/fundamentals/code-analysis/quality-rules/ca1823.md b/docs/fundamentals/code-analysis/quality-rules/ca1823.md index 2ebc222c53912..9b2b0afeb05dc 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca1823.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca1823.md @@ -10,6 +10,8 @@ helpviewer_keywords: - CA1823 author: gewarren ms.author: gewarren +dev_langs: +- CSharp --- # CA1823: Avoid unused private fields @@ -33,6 +35,10 @@ Private fields were detected that do not appear to be accessed in the assembly. To fix a violation of this rule, remove the field or add code that uses it. +## Example + +:::code language="csharp" source="snippets/csharp/all-rules/ca1823.cs" id="snippet1"::: + ## When to suppress warnings It is safe to suppress a warning from this rule. @@ -60,3 +66,4 @@ For more information, see [How to suppress code analysis warnings](../suppress-w - [CA1812: Avoid uninstantiated internal classes](ca1812.md) - [CA1801: Review unused parameters](ca1801.md) +- [Remove unread private member (IDE0052)](../style-rules/ide0052.md) diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1823.cs b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1823.cs new file mode 100644 index 0000000000000..255d7d13a5766 --- /dev/null +++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1823.cs @@ -0,0 +1,24 @@ +namespace ca1823 +{ + // + public class User + { + private readonly string _firstName; + private readonly string _lastName; + + // CA1823: Unused field '_age' + private readonly int _age; + + public User(string firstName, string lastName) + { + _firstName = firstName; + _lastName = lastName; + } + + public string GetFullName() + { + return $"My name is {_firstName} {_lastName}"; + } + } + // +}