Skip to content

use-literal-suffix

C#stylefix: safedefault: offcsharp/stylecop

Reports a numeric literal cast to long, ulong, uint, float, double or decimal when the literal’s own type differs: (long)1 is 1L. Hexadecimal and binary literals cast to a floating-point type are not reported, since they have no suffix. The fix writes the suffix.

The suffix gives the literal its type directly. A cast does the same at run time or as a constant, and it hides that the literal is a number of another type.

Reported
class A {
int a, b;
Nullable<int> n = (long)1 < 2 ? null : null;
void F(object o, int i) {
...
var h = (float)1 + (double)2.5;
}
}
After the fix
class A {
int a, b;
Nullable<int> n = 1L < 2 ? null : null;
void F(object o, int i) {
...
var h = 1F + (double)2.5;
}
}
csharp:
lint:
rules:
use-literal-suffix: warn # off (default), warn, error

Enabled by the presets: csharp/stylecop.

Suppress one line with sudsy-disable-next-line use-literal-suffix in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
StyleCop SA1139 full