Skip to content

Add fixed example for CA rule #32957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2022
Merged
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
34 changes: 24 additions & 10 deletions docs/fundamentals/code-analysis/quality-rules/ca1708.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "CA1708: Identifiers should differ by more than case (code analysis)"
description: "Learn about code analysis rule CA1708: Identifiers should differ by more than case"
ms.date: 03/11/2019
ms.date: 12/08/2022
ms.topic: reference
f1_keywords:
- "IdentifiersShouldDifferByMoreThanCase"
Expand All @@ -14,11 +14,11 @@ ms.author: gewarren
---
# CA1708: Identifiers should differ by more than case

| | Value |
|-|-|
| **Rule ID** |CA1708|
| **Category** |[Naming](naming-warnings.md)|
| **Fix is breaking or non-breaking** |Breaking|
| | Value |
| ----------------------------------- | ---------------------------- |
| **Rule ID** | CA1708 |
| **Category** | [Naming](naming-warnings.md) |
| **Fix is breaking or non-breaking** | Breaking |

## Cause

Expand All @@ -30,11 +30,9 @@ By default, this rule only looks at externally visible types, members, and names

Identifiers for namespaces, types, members, and parameters cannot differ only by case because languages that target the common language runtime are not required to be case-sensitive. For example, Visual Basic is a widely used case-insensitive language.

This rule fires on publicly visible members only.

## How to fix violations

Select a name that is unique when it is compared to other identifiers in a case-insensitive manner.
Select a name that's unique when it's compared to other identifiers in a case-insensitive manner.

## When to suppress warnings

Expand All @@ -54,4 +52,20 @@ You can configure this option for just this rule, for all rules, or for all rule

The following example demonstrates a violation of this rule.

:::code language="csharp" source="snippets/csharp/all-rules/ca1708.cs" id="snippet1":::
```csharp
public class Class1
{
protected string someName;
public string SomeName => someName;
}
```

The following example shows one way to fix the violation

```csharp
public class Class1
{
protected string _someName;
public string SomeName => _someName;
}
```

This file was deleted.