我不得不处理用大号码进行计算的代码,例如,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