Skip to content

BRO1135: Integer literal suffixes should be upper case

The suffix of an integer literal is upper case: 1L, 2U, 3UL. Not a StyleCop rule (requested in StyleCop issue #1563; Sonar S818).

Example

Before

public class Limits
{
    public const long Max = 100l;
    public const uint Mask = 0xFFu;
    public const ulong Big = 1ul;
}

After

public class Limits
{
    public const long Max = 100L;
    public const uint Mask = 0xFFU;
    public const ulong Big = 1UL;
}

Why

A lower-case l looks like the digit 1: 100l reads as 1001. The C# specification recommends L, and the compiler warns about l (CS0078) but has no fix for it. u follows so that a suffix is written one way.

How the fix works

Only the suffix's letters change (ul, Ul and uL become UL; lu becomes LU). Hex and binary literals work the same way: their suffix letters can't be digits. BRO1122, which replaces casts with suffixes, writes upper case, so the two rules agree.

Configuration

[*.cs]
# all (default): every integer suffix letter upper case
# l_only: only 'l' must be upper case
# lone_l: only a suffix that is just 'l' ('1l'), like Sonar's S818; '1ul' and '1lu' are fine
stylebro_upper_case_literal_suffixes = all

With l_only, only a suffix with a lower-case l is reported, and the fix upper-cases just the l; a u stays as written.

// Before (stylebro_upper_case_literal_suffixes = l_only)
public const long Max = 100l;
public const uint Mask = 0xFFu;
public const ulong Big = 1ul;

// After
public const long Max = 100L;
public const uint Mask = 0xFFu;
public const ulong Big = 1uL;

With lone_l, only a suffix that is just l is reported (100l becomes 100L); 1ul, 1Ul and 1lu stay. That is exactly what Sonar's S818 reports, and what stylebro-migrate writes for a repository that enforces S818.

Not reported

  • Real literals: 1.5f, 2d and 3m stay as they are, and so does the exponent's e. Lower case is the common way to write them (most of the surveyed repositories use f, d and m), and none of these letters looks like a digit.

Compared with StyleCop

StyleCop has no such rule. Sonar's S818 reports only a suffix that is just l; BRO1135 also upper-cases u and an l next to a u unless stylebro_upper_case_literal_suffixes = lone_l. stylebro-migrate turns it off (see Rules beyond StyleCop).