X

Digit Separators and Binary Literals in C#

Csharp-MS-Dotnet

In C#7 there are Digit Separators and Binary Literals which were added. One may wonder what these are? Basically you can replace long number values with underscore (_) such that code readability is improved.

Let me give you couple of examples of it to make it clear.

//old way of 
var myBigNumber = 12345678901234567890;

//new way with digital separators
var myBigNumberNewWay = 123_456_789_012_345_678_90;

Neat but it doesnโ€™t end there you can also use it for Binary literals and Hex also, like the examples below, where they all are 2020 the year we all despise ๐Ÿ™‚


var myInt = 2020;

var myBinary = 0b11_11_11_00_100;

var myHex = 0x7_E4;

Summary

I hope the C#7 Digital Separators and Binary Literals will give you a hand in writing more clear code ๐Ÿ™‚

Categories: .NET C#
Tags: csharpdotnet
Taswar Bhatti:
Related Post