In C#, having conditions that are always true (or always false) is generally a bad practice because it leads to unreachable code, logic errors, and maintainability issues.
How to Remediate
Replace true with a meaningful, dynamic condition.
Use variables, method results, or flags to evaluate logic properly.
Remove useless condition branches
Non-Compliant Code Examples
// Count cannot be negativeif(myList.Count<0){// do something}// use double.IsNan insteadif(x==double.NaN){// do something}
Compliant Code Examples
if(myList.Count>=0){// do something}if(double.isNaN(x)){// do something}
Seamless integrations. Try Datadog Code Security
Datadog Code Security
Try this rule and analyze your code with Datadog Code Security
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 Security scans to your CI pipelines