I had to deal with the code that does calculation with big number e.g.
long foo = 6235449243234;
This is hard to tell what is the order of magnitude. I'd like to write it
long foo = 6_235_449_243_234;
Or
long foo = @6 235 449 243 234;
But C# doesn't have these features. How to make number literals more readable?
Comment it
long foo = 6235449243234; // 6 23...
Convert it from string
long foo = LiteralConverter.toLong(@"6_235_449_243_234");
int mask = LiteralConverter.toInt("b0111_0000_0100_0000");
Any other options?
Define named constants for these literals, and use comments to explain what the number represents.
class MyClass {
///
/// This constant represents cost of a breakfast in Zimbabwe:
/// 6,235,449,243,234
///
const long AvgBreakfastPriceZimbabweanDollars = 6235449243234;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With