Skip to content
Open
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
13 changes: 13 additions & 0 deletions docs/fundamentals/code-analysis/quality-rules/ca2251.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ The result of a call to <xref:System.String.Compare%2A?displayProperty=nameWithT

To fix violations of this rule, replace the expression comparing the result of <xref:System.String.Compare%2A?displayProperty=nameWithType> with a call to <xref:System.String.Equals%2A?displayProperty=nameWithType>.

## Example

```csharp
string leftValue = "...";
string rightValue = "...";

// This code violates the rule.
bool areEqualUsingCompare = string.Compare(leftValue, rightValue, StringComparison.OrdinalIgnoreCase) == 0;

// This code satisfies the rule.
bool areEqualUsingEquals = string.Equals(leftValue, rightValue, StringComparison.OrdinalIgnoreCase);
```

## When to suppress warnings

It is safe to suppress warnings from this rule.
Expand Down