C# Digit Separator

Note: For all my articles on C#.Net / Visual Studio, please visit here.


Sometimes, when you want to represent a big integer or long literal in C# code, it becomes less readable and there are chances to misspell a digit too.

Consider the following example of a C# constant,

const int assumedPopulation = 1122339654;
You will find the one line code is neat and clean, but the numeric value/literal is not so readable.

It would be better if there was some digit separator like we have in Excel for numbers. Then, the number would be easy to read, like below.


With C# 7, Microsoft has introduced a digit separator. While it’s not the regular digit separator “comma” which we use everywhere, it’s underscore.

In C# 7, the same line of code can be written as,

const int assumedPopulation = 1_122_339_654;
Doesn’t it make the number quite easily readable?
And this digit separator does not affect its display on UI.

Write the following code in a C# 7 console app (With VS 2017), and check the output on the console. The digit separator will not be printed on console.

static void Main(string[] args)  
   const int assumedPopulation = 1_122_339_654;  



The C# 7 digit separator can be used with long, ulong, decimal, int, uint, short, ushort, double, byte, float data types.

Note: This article was originally published by me on C# Corner website here.

Leave a Reply


WordPress.com Logo


Google photo


Twitter picture


Facebook photo


Connecting to %s