Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/fundamentals/code-analysis/quality-rules/ca1823.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ helpviewer_keywords:
- CA1823
author: gewarren
ms.author: gewarren
dev_langs:
- CSharp
---
# CA1823: Avoid unused private fields

Expand All @@ -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.
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace ca1823
{
//<snippet1>
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}";
}
}
//</snippet1>
}
Loading