dotnet / dotnet/roslynator

Feature request: New analyzer and fix: Replace String.Compare(.......) == 0 with String.Equals

Open
#396 3 comments 0 reactions 0 assignees View on GitHub
Area-Analyzers Feature Request
Dominant language
C#
Stars
3.5k
Forks
294
Avg merge
2h 30m
Merged PRs (30d)
4

Description

In some case the `String.Compare` where the result is checked for equality to zero could be replaced with `String.Equals`. At least the variants that take `string, string`:

```
String.Compare(a, b) == 0;
String.Equals(a, b, StringComparison.CurrentCulture);
```

And `string, string, bool`:

```
String.Compare(a, b, true) == 0;
String.Equals(a, b, StringComparison.CurrentCultureIgnoreCase);
```

I'm not really sure about the other overloads of `String.Compare` though.

It would be handy to have an analyzer that reports these cases and also a fix for these.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.