Storing Variables for Global Use In Application
I am having some trouble with a simple problem of storing variables within my program. I am retrieving settings from within an XML file, which is working fine. But I need to store the variables in my program for the duration of its execution. I figured I need to store them in a separate .cs (Class) file within the project, possibly as Attributes. Then use the Set and Get methods to control the values. I do want the values to be stored in a separate class of their own so that they can be controlled and used by methods in several other classes.
* Am I approaching the problem the correct way?
* If I do the following, will the values remain set, unless modified, until the program terminates?
// Start of Settings Class
using System;
namespace Settings
{
// Main class, which will have several sub-classes
internal class clsMain
{
// Sub-class, which is one of several classes within the Main class
internal class clsSetting : Attribute
{
protected double dValue;
public double DoubleValue
{
get{return dValue;}
set{dValue = value;}
}
protected string sValue;
public double StringValue
{
get{return sValue;}
set{sValue = value;}
}
}
}
}
// End of Settings Class
// Sample code used in different class, within a different .cs file in the project
private clsMain.clsSetting Setting = new clsMain.clsSetting();
// Store values in Settings
Setting.DoubleValue = 12345;
Setting.StringValue = "TestValue";
// Retrieve values from Settings
MessageBox.Show("DoubleValue = " + Setting.DoubleValue.ToString());
MessageBox.Show("StringValue = " + Setting.StringValue());