Digit Separator in C#.NET

Digit Separator in C#.NET

Readability means clean code which means professionalism

C#.NET is a general-purpose programming language always on the mission to keep improving in every aspect, C# has improved its readability a lot with the period. Digit separation is part of readability improvement which was launched in C# 7.0

Let's say you are saving a large number into an integer the readability becomes complex so you can use the underscore symbol to make your program more readable.

for example

int hard_to_read = 150000;
int easy_to_read = 150_000;

In the output, it will show you a simple number like


int easy_to_read = 150_000;
Console.WriteLine(easy_to_read);

//Output : 150000

But you have to take care of a few things

  • Do not use the _ in the start of the value

  • Do not use _ at the end of the value

  • Do not use with decimals like 15_.45