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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s