[英]How can i throw exception to the value from app.config file
I was said to import sales tax rate from app.config file. 据说我要从app.config文件导入销售税率。 In my app.config file i have two tax value GST and PST.
在我的app.config文件中,我有两个税值GST和PST。 How can i import this string value to my program code plus convert to decimal value and then add it .
我如何将这个字符串值导入到我的程序代码中,再转换为十进制值,然后将其添加。 I have done till and i am receiving an error of throw exception.
我已经做完了,并且收到抛出异常的错误。 How can i throw exception ??
我如何抛出异常? Thanks for the help in advance.
我在这里先向您的帮助表示感谢。
public decimal SalesTax
{
get
{
decimal rateGST = Decimal.Parse(ConfigurationManager.AppSettings["rateGST"]);
decimal ratePST = Decimal.Parse(ConfigurationManager.AppSettings["ratePST"]);
return Subtotal * (rateGST + ratePST);
}
}
my App.config file is as below 我的App.config文件如下
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<!--Government Sales Tax-->
<add key ="rateGST" value="5"/>
<!--Provincial Sales Tax-->
<add key="ratePST" value="8"/>
</appSettings>
</configuration>
Try the following 尝试以下
using System;
namespace demo
{
class Class1
{
public decimal Subtotal { get; set; } //= 5;
public decimal SalesTax
{
get
{
decimal rateGST = Decimal.Parse(Properties.Settings.Default.rateGST);
decimal ratePST = Decimal.Parse(Properties.Settings.Default.ratePST);
decimal result = Subtotal * (rateGST + ratePST);
return result;
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.