During development, often we use literal in our code. They are the fixed values which may not alter during the code execution. Sometime these values are large, and sometime small. If it is small, it’s ok. If it long representation, it could be hard to read. Making them separate could help read them better. C# 7.0 allows ‘_’ (underscore) in literals for improving the readability of your code.
To improve the readability, you can use the ‘_’ in between the number as shown in below snippet.
var number = 123_456_1617;
‘_’ used here just link a Digit Separator. Having ‘_’ has no effects on the values, and you can use the ‘number’ variable as like another variable.
Here is another example of using ‘_’ with constant values.
const int number = 123_456_1617;
Related Tip: Directly throw Exception as an Expression – Throw expressions in C# 7.0
Not only with the digits, you can use the Binary Literals for representing the binary number.
This one is a very small enhancement, however it helps you make your code more readable.
Hope this helps.
Pingback: Dew Drop - August 4, 2017 (#2535) - Morning Dew