Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i design application using c sharp.
in that i have threecolumn as follows.
Rental cost ,Diesel service, Service Tax.


Rental Cost 231270
Diesel ser 19767
Ser Tax 30124(231270 + 19767 * 12/100).
Code as follows;

double o = Convert.ToDouble(txt_rentalcost.Text);
double p = Convert.ToDouble(txt_dieselservice.Text);
txt_servicetax.Text = Math.Round((o + p) * 0.12).ToString();

i am doing service tax calculation at that time service tax is 12 percentage.suppose in next year service tax percentage is 12.36.

i post the above question you said that we can write the code in App.config.

In App.config how to write the code.please help me.first time i am using App.config help me.


?xml version="1.0" encoding="utf-8"?>
<configuration>
Posted

Adding Keys in app.config file
XML
<appSettings>
    <add key="author" value="Palanisamy Veerasingam"/>
    <add key="article" value="Configuration Sections"/>
</appSettings>


Retreiving the Key value in your application
C#
return (ConfigurationSettings.AppSettings["author"]);



Check this article for more information
Understanding Section Handlers - App.config File[^]
 
Share this answer
 
Use a settings file:

In Visual Studio, go to "project properties" -> "Settings"

In the shown datagrid add a row with "Name"->TaxPercentage, Type=double, Scope=Application, Value=12
this will result in a new section in your app.config:

XML
<configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
        <section name="WindowsFormsApplication1.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
</configSections>


and the stored setting:
XML
<applicationSettings>
        <WindowsFormsApplication1.Properties.Settings>
            <setting name="Setting" serializeAs="String">
                <value>0</value>
            </setting>
        </WindowsFormsApplication1.Properties.Settings>
    </applicationSettings>


to access your settings in Code just add a using directive like:
C#
using WindowsFormsApplication1.Properties;


and access your configurable value with:
C#
double value = Settings.Default.TaxPercentage;


this will give you a leightweight but typesafe configurable value in your application
- leightweight, cause you don´t have to write custom config sections, what i prefer if i have to manage many configurable parameters of my application/service/etc.
- typesafe, cause the configuration-system will make sure that the your setting will always be of the expected type

refer this link [^]for detailed information
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900