Skip to content

Latest commit

 

History

History
40 lines (28 loc) · 768 Bytes

File metadata and controls

40 lines (28 loc) · 768 Bytes

Pattern: Missing use of string.Method(char)

Issue: -

Description

string.Method(string) is used when string.Method(char) was available.

The target methods on string for these rules:

  • StartsWith
  • EndsWith
  • IndexOf
  • LastIndexOf

The following table summarizes the conditions for each of the related rule IDs.

Example of incorrect code:

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

Example of correct code:

public bool StartsWithLetterI()
{
    var testString = "I am a test string.";
    return testString.StartsWith('I');
}

Further Reading