我不得不處理用大號碼進行計算的代碼,例如,long integer literals
long foo = 6235449243234;
這很難說是什麼數量級。我希望把它寫
long foo = 6_235_449_243_234;
或者
long foo = @6 235 449 243 234;
但是C#不具備這些功能。如何讓數字文字更具可讀性?
評論
long foo = 6235449243234; // 6 23...
從字符串
long foo = LiteralConverter.toLong(@"6_235_449_243_234");
int mask = LiteralConverter.toInt("b0111_0000_0100_0000");
任何其他選項轉換呢?
的可能重複(http://stackoverflow.com/questions/8488989/can -i-declare-constant-integers -with-a-thousand-separator-in-c) – CodesInChaos 2012-02-04 19:04:52
在'LiteralConverter.toLong'示例中,'@'不是必需的。 – luiscubal 2012-02-04 19:05:48
該語言應該支持在數字文字中使用'_'。我沒有看到解析器無法支持的原因。 – 2015-10-23 09:24:14