To check is a string contains a sub-string, use Contains() and do not use proxy functions such as IndexOf.
Non-Compliant Code Examples
classMyClass{publicstaticvoidprocessString(strings){if(strings.IndexOf(s)==-1){// do something}if(strings.IndexOf(s)<0){// do something else}if(strings.IndexOf(s)>=0){// or do this}}}
Compliant Code Examples
classMyClass{publicstaticvoidprocessString(strings){if(!strings.Contains(s)){// do something}}}
Seamless integrations. Try Datadog Code Analysis
Datadog Code Analysis
Try this rule and analyze your code with Datadog Code Analysis
How to use this rule
1
2
rulesets:- csharp-best-practices # Rules to enforce C# best practices.
Create a static-analysis.datadog.yml with the content above at the root of your repository
Use our free IDE Plugins or add Code Analysis scans to your CI pipelines