All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.csharp.S2198.html Maven / Gradle / Ivy

There is a newer version: 10.2.0.105762
Show newest version

Why is this an issue?

Certain mathematical comparisons will always return the same value, and should not be performed.

Specifically, the following comparisons will return either always true or always false depending on the kind of comparison:

  • comparing a char with a numeric constant that is outside of the range of char
  • comparing a float with a numeric constant that is outside of the range of float
  • comparing a long with a numeric constant that is outside of the range of long
  • comparing a ulong with a numeric constant that is outside of the range of ulong
  • etc.

Noncompliant code example

float f = 42.0f;
if (f <= double.MaxValue) { } // Noncompliant: always true
if (f > double.MaxValue) { }  // Noncompliant: always false

Resources

Documentation





© 2015 - 2024 Weber Informatics LLC | Privacy Policy