Tip #003
Make big numbers readable
About this tip
The compiler ignores underscores in numeric literals. They work in hex and binary too. How many zeroes? 1_000_000_000 vs 1000000000. It is available since C# 7. The key line is var easyBillion = 1_000_000_000 in numbers.cs. It fits in 12 lines; run it with dotnet run numbers.cs.
Did this tip save you some time? Consider buying me a coffee to fuel the next one.
Buy me a coffeeCode
// how many zeroes is a billion?var billion = 1000000000;
// oh! nine zeroes.var easyBillion = 1_000_000_000;Console.WriteLine(billion == easyBillion);
// works with hex and binary toovar color = 0xFF_EF_44_44;var flags = 0b1010_0101;Console.WriteLine(color.GetType());Console.WriteLine(flags);Output
$ dotnet run numbers.csTrueSystem.UInt32165