Skip to content

Digit separators C# 7.0readability

Allow numeric literals to containing the `_` character as a visual aid

C# has allowed numeric constants since the start but previously there was no valid syntax for separating long or confusing sequences of numeric digits.

C# 7.0 allows _ to be placed anywhere you like within your numeric literals to aid in readability. They are ignored entirely at compile time.

Code

C#
const utf16littleEndian = 0xFE_FF;
const utf16bigEndian    = 0xFF_FE;
C#
const utf16littleEndian = 0xFEFF;
const utf16bigEndian    = 0xFFFE;

Notes

More information