Skip to content

[Analyzer] Using StartsWith instead of IndexOf == 0 #78608

@stephentoub

Description

@stephentoub

We should write an analyzer that flags uses of IndexOf that's comparing the resulting index to 0, e.g.
https://grep.app/search?q=%5C.IndexOf%5C%28.%2A%3F%5C%29%20%3D%3D%200&regexp=true&case=true&filter[lang][0]=C%23
Such use would be much better off with StartsWith, as IndexOf will search the entire string vs StartsWith which will only compare at the beginning.

Performance rules Category
Severity = suggestion

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedAPI was approved in API review, it can be implementedarea-System.Globalizationcode-analyzerMarks an issue that suggests a Roslyn analyzercode-fixerMarks an issue that suggests a Roslyn code fixerpartner-impactThis issue impacts a partner who needs to be kept updated

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions