我正在使用在线转换工具将VB代码转换为C#。 VB的代码是:Can Convert.ToDecimal可以返回一个常量吗?
Private Const constant1 As Decimal = CDec(37.5)
结果:
private const decimal constant1 = Convert.ToDecimal(37.5);
然而,编译时的错误消息:
表达被分配给 '常量1' 必须是恒定的
为了消除错误,我修改了代码:
private const decimal constant1 = (decimal)37.5;
有谁能告诉为什么Convert.ToDecimal无法返回常量吗?
,因为回报率取决于值被转换 – Plutonix
参考数字后缀:http://stackoverflow.com/questions/3569695/c-sharp-numeric-suffixes – GSP