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:
<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:
<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:
using WindowsFormsApplication1.Properties;
and access your configurable value with:
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