From 355fafd961339b278c9d854948ab276d40bf7f60 Mon Sep 17 00:00:00 2001 From: kurnakovv Date: Sat, 11 Oct 2025 15:00:23 +0900 Subject: [PATCH] Add code example for CA2251 rule (#49091) --- .../code-analysis/quality-rules/ca2251.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2251.md b/docs/fundamentals/code-analysis/quality-rules/ca2251.md index bda71465dac68..8e0c270a09ef4 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2251.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2251.md @@ -32,6 +32,19 @@ The result of a call to with a call to . +## 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.