use-literal-suffix
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”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; }}class A { int a, b; Nullable<int> n = 1L < 2 ? null : null; void F(object o, int i) {... var h = 1F + (double)2.5; }}Configuration
Section titled “Configuration”csharp: lint: rules: use-literal-suffix: warn # off (default), warn, errorEnabled by the presets: csharp/stylecop.
Suppress one line with sudsy-disable-next-line use-literal-suffix in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| StyleCop | SA1139 |
full |