From ab0b220eda56850f1a7e27d8f679e084f6cc320d Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Thu, 6 Jun 2024 13:26:22 -0700 Subject: [PATCH 1/3] Use String.Contains (uppercase) --- .../fundamentals/code-analysis/quality-rules/ca1847.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca1847.md b/docs/fundamentals/code-analysis/quality-rules/ca1847.md index 89b804a2d9ee3..f6ba57c845975 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca1847.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca1847.md @@ -1,6 +1,6 @@ --- title: "CA1847: Use char literal for a single character lookup" -description: "Use string.Contains(char) instead of string.Contains(string) when searching for a single character" +description: "Use String.Contains(char) instead of String.Contains(string) when searching for a single character" ms.date: 03/03/2021 f1_keywords: - "CA1847" @@ -12,23 +12,23 @@ dev_langs: - VB --- -# CA1847: Use string.Contains(char) instead of string.Contains(string) with single characters +# CA1847: Use String.Contains(char) instead of String.Contains(string) with single characters | Property | Value | |-------------------------------------|-------------------------------------------------------------------------------------| | **Rule ID** | CA1847 | -| **Title** | Use string.Contains(char) instead of string.Contains(string) with single characters | +| **Title** | Use String.Contains(char) instead of String.Contains(string) with single characters | | **Category** | [Performance](performance-warnings.md) | | **Fix is breaking or non-breaking** | Non-breaking | | **Enabled by default in .NET 8** | As suggestion | ## Cause -`string.Contains(string)` is used when `string.Contains(char)` was available. +`String.Contains(string)` is used when `String.Contains(char)` is available. ## Rule description -When searching for a single character, using `string.Contains(char)` offers better performance than `string.Contains(string)`. +When searching for a single character, `String.Contains(char)` offers better performance than `String.Contains(string)`. ## How to fix violations From 0b2394d9ed44af7654e25f5afc0a6ad4feff2347 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Thu, 6 Jun 2024 13:27:25 -0700 Subject: [PATCH 2/3] Update performance-warnings.md --- .../code-analysis/quality-rules/performance-warnings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/performance-warnings.md b/docs/fundamentals/code-analysis/quality-rules/performance-warnings.md index d3b9cb286b1aa..dc28cd1200fb5 100644 --- a/docs/fundamentals/code-analysis/quality-rules/performance-warnings.md +++ b/docs/fundamentals/code-analysis/quality-rules/performance-warnings.md @@ -56,7 +56,7 @@ Performance rules support high-performance libraries and applications. | [CA1844: Provide memory-based overrides of async methods when subclassing 'Stream'](ca1844.md) | To improve performance, override the memory-based async methods when subclassing 'Stream'. Then implement the array-based methods in terms of the memory-based methods. | | [CA1845: Use span-based 'string.Concat'](ca1845.md) | It is more efficient to use `AsSpan` and `string.Concat`, instead of `Substring` and a concatenation operator. | | [CA1846: Prefer `AsSpan` over `Substring`](ca1846.md) | `AsSpan` is more efficient than `Substring`. `Substring` performs an O(n) string copy, while `AsSpan` does not and has a constant cost. `AsSpan` also does not perform any heap allocations. | -| [CA1847: Use char literal for a single character lookup](ca1847.md) | Use `string.Contains(char)` instead of `string.Contains(string)` when searching for a single character. | +| [CA1847: Use char literal for a single character lookup](ca1847.md) | Use `String.Contains(char)` instead of `String.Contains(string)` when searching for a single character. | | [CA1848: Use the LoggerMessage delegates](ca1848.md) | For improved performance, use the `LoggerMessage` delegates. | | [CA1849: Call async methods when in an async method](ca1849.md) | In a method which is already asynchronous, calls to other methods should be to their async versions, where they exist. | | [CA1850: Prefer static `HashData` method over `ComputeHash`](ca1850.md) | It's more efficient to use the static `HashData` method over creating and managing a `HashAlgorithm` instance to call `ComputeHash`. | From 01eb35053fdea823bc885d8da8e7db97436d8be3 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Thu, 6 Jun 2024 13:27:56 -0700 Subject: [PATCH 3/3] Update index.md --- docs/fundamentals/code-analysis/quality-rules/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/index.md b/docs/fundamentals/code-analysis/quality-rules/index.md index c3066b924a596..90df4991a1fd2 100644 --- a/docs/fundamentals/code-analysis/quality-rules/index.md +++ b/docs/fundamentals/code-analysis/quality-rules/index.md @@ -147,7 +147,7 @@ The following table lists code quality analysis rules. > | [CA1844: Provide memory-based overrides of async methods when subclassing 'Stream'](ca1844.md) | To improve performance, override the memory-based async methods when subclassing 'Stream'. Then implement the array-based methods in terms of the memory-based methods. | > | [CA1845: Use span-based 'string.Concat'](ca1845.md) | It is more efficient to use `AsSpan` and `string.Concat`, instead of `Substring` and a concatenation operator. | > | [CA1846: Prefer `AsSpan` over `Substring`](ca1846.md) | `AsSpan` is more efficient than `Substring`. `Substring` performs an O(n) string copy, while `AsSpan` does not and has a constant cost. `AsSpan` also does not perform any heap allocations. | -> | [CA1847: Use char literal for a single character lookup](ca1847.md) | Use `string.Contains(char)` instead of `string.Contains(string)` when searching for a single character. | +> | [CA1847: Use char literal for a single character lookup](ca1847.md) | Use `String.Contains(char)` instead of `String.Contains(string)` when searching for a single character. | > | [CA1848: Use the LoggerMessage delegates](ca1848.md) | For improved performance, use the `LoggerMessage` delegates. | > | [CA1849: Call async methods when in an async method](ca1849.md) | In a method which is already asynchronous, calls to other methods should be to their async versions, where they exist. | > | [CA1850: Prefer static `HashData` method over `ComputeHash`](ca1850.md) | It's more efficient to use the static `HashData` method over creating and managing a `HashAlgorithm` instance to call `ComputeHash`. |