C# has allowed numeric literals 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 between the digits of your numeric literals to aid in readability. They are ignored entirely at compile time.
Code
csharp
const int maxUploadBytes = 10_000_000;
const int utf16bigEndian = 0xFE_FF;
const int utf16littleEndian = 0xFF_FE;csharp
const int maxUploadBytes = 10000000;
const int utf16bigEndian = 0xFEFF;
const int utf16littleEndian = 0xFFFE;Notes
- Separators can be repeated (
1__000) but cannot appear at the end of a literal or next to the decimal point, exponent or type suffix - Works with decimal, hex and Binary literals C# 7.0
- Extended to directly after the
0xor0bprefix by Numeric literal leading underscores C# 7.2