C#

C#

Made by DeepSource

Consider using string.Contains instead of comparing the result of string.IndexOf CS-R1110

Anti-pattern
Major
Autofix

The method string::IndexOf() returns the index of the character/substring in a string. If no such character/substring exists, -1 is returned. However, the expression string.IndexOf(arg) > -1 effectively checks if arg exists within a string and is equivalent to string.Contains(arg). Consider rewriting it that way instead to make the intent clearer.

Bad Practice

var exists = name.IndexOf('a') > -1;

Recommended

var exists = name.Contains('a');