我怎样才能对 app.config 文件中的值抛出异常
How can i throw exception to the value from app.config file
据说我要从 app.config 文件中导入销售税率。在我的 app.config 文件中,我有两个税值 GST 和 PST。我如何将这个字符串值导入我的程序代码并转换为十进制值然后添加它。我已经完成了,我收到了抛出异常的错误。我怎样才能抛出异常??提前感谢您的帮助。
public decimal SalesTax
{
get
{
decimal rateGST = Decimal.Parse(ConfigurationManager.AppSettings["rateGST"]);
decimal ratePST = Decimal.Parse(ConfigurationManager.AppSettings["ratePST"]);
return Subtotal * (rateGST + ratePST);
}
}
我的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>
尝试以下方法
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;
}
}
}
}
据说我要从 app.config 文件中导入销售税率。在我的 app.config 文件中,我有两个税值 GST 和 PST。我如何将这个字符串值导入我的程序代码并转换为十进制值然后添加它。我已经完成了,我收到了抛出异常的错误。我怎样才能抛出异常??提前感谢您的帮助。
public decimal SalesTax
{
get
{
decimal rateGST = Decimal.Parse(ConfigurationManager.AppSettings["rateGST"]);
decimal ratePST = Decimal.Parse(ConfigurationManager.AppSettings["ratePST"]);
return Subtotal * (rateGST + ratePST);
}
}
我的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>
尝试以下方法
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;
}
}
}
}