如何设置恒定的十进制值
问题描述:
我使用C#在我的配置类
I'm using C# to set a default value for a decimal value in my config class
public class ConfigSection : ConfigurationSection
{
[ConfigurationProperty("paymentInAdvanceAmount", **DefaultValue = 440m**)]
public decimal PaymentInAdvanceAmount
{
get { return (decimal)base["paymentInAdvanceAmount"]; }
set { base["paymentInAdvanceAmount"] = value; }
}
}
但它不会被编译并抛出误差
but it won't be compiled and throws an error
的属性参数必须是常量表达式,typeof运算表达式
我发现一个帖子称:这不是一个错误。1000M仅仅是速记新的十进制数(1000),这涉及到一个方法调用,这意味着它不被视为一个常量只是因为编译可以让你假装。这是一个不变的大部分时间,并不意味着你可以将所有的时间。
现在,我该如何解决办法呢?
Now, how do I workaround it?
答
我终于找到了它,我进入440,而不是440米或440
它得到了编译和运行良好
I finally found out it I enter "440" instead of 440m or 440. It got compiled and runs well