To declare an application wide variable, declare it in you app.config file
<appSettings>
<add key="your_variable_name" value="your_variable_value"/>
</appSettings>
To get your variable in code:
string YourVariable= ConfigurationManager.AppSettings["your_variable_name"];
I hope this is what you were asking and that this answer helps :)
Edit: Added way to edit app.config file
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings.Remove("your_variable_name");
your_variable_new_value = your_variable_value + 1;
config.AppSettings.Settings.Add("your_variable_name", your_variable_new_value);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
Source:
How to change app.config file at runtime[
^]