The Cobra programming language has a useful feature where you can use underscores in numeric literals to improve readability. For example, the following are equivalent, but the second line is easier to read:
x = 1000000
x = 1_000_000 # obviously 1 million
Is there anything equivalent for C#?
Answer as of C# 7
Yes, this is supported in C# 7. But be aware that there’s no validation that you’ve put the underscores in the right place:
Answer from 2011
No, there’s nothing like that in C#. You could do:
but that’s about as nice as it gets.
(Note that this enhancement went into Java 7 as well… maybe one day it will be introduced in C#.)