c# - How can i throw exception to the value from app.config file -
i said import sales tax rate app.config file. in app.config file have 2 tax value gst , pst. how can import string value program code plus convert decimal value , add . have done till , receiving error of throw exception. how can throw exception ?? in advance.
public decimal salestax { { decimal rategst = decimal.parse(configurationmanager.appsettings["rategst"]); decimal ratepst = decimal.parse(configurationmanager.appsettings["ratepst"]); return subtotal * (rategst + ratepst); } } my app.config file below
<?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 following
using system; namespace demo { class class1 { public decimal subtotal { get; set; } //= 5; public decimal salestax { { decimal rategst = decimal.parse(properties.settings.default.rategst); decimal ratepst = decimal.parse(properties.settings.default.ratepst); decimal result = subtotal * (rategst + ratepst); return result; } } } }
Comments
Post a Comment