Skip to content

Numeric literal leading underscores C# 7.2readability

Allow underscores to be used before the first digit in a numeric literal.

C# 7.0 gave us digit separators C# 7.0 but did not permit them directly after the 0x or 0b prefix of a hexadecimal or binary literal.

C# 7.2 permits the _ character to also be used between the prefix and the first digit.

Code ​

csharp
const int utf16bigEndian    = 0x_FE_FF;
const int utf16littleEndian = 0x_FF_FE;
csharp
const int utf16bigEndian    = 0xFE_FF;
const int utf16littleEndian = 0xFF_FE;

Notes ​

  • Decimal literals still cannot start with _ as _123 would be an identifier

More information ​

Powered by Intracia