All rules
CA1847Performance Enabled by default: As suggestion

Use String.Contains(char) instead of String.Contains(string) with single characters

Use String.Contains(char) instead of String.Contains(string) with single characters

Microsoft docs

Description

When searching for a single character, String.Contains(char) offers better performance than String.Contains(string).

Cause

String.Contains(string) is used when String.Contains(char) is available.

How to fix violations

In general, the rule is fixed simply by using a char literal instead of a string literal.

This code can be changed to use a char literal instead.

Example

public bool ContainsLetterI()
{
    var testString = "I am a test string.";
    return testString.Contains("I");
}

When to suppress

Suppress a violation of this rule if you're not concerned about the performance impact of the search invocation in question.

Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0