A tried and tested way I have used is to design a settings container class.
This container class can have sub classes for different types of setting categories.
It works well since you reference your "settings" via property name and therefore if something changes in future, you will get compile time errors. It is also expandible, since you can always create new settings by adding more properties to your individual setting classes and assign default values to the private variable of a property that will be used should that specific setting not exist in an older version of your application. Once the new container is saved, the new settings will be persisted as well.
Another advantage is the obvious human / computer readability of XML which is nice for settings.
To save, serialize the container object to xml data, then write the data to file. To load, read the data from file and deserialize back into your settings container class.
To serialize via standerd dotnet code:
public static string SerializeToXMLString(object ObjectToSerialize)
MemoryStream mem = new MemoryStream();
System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(ObjectToSerialize.GetType());
ser.Serialize(mem,ObjectToSerialize);
ASCIIEncoding ascii = new ASCIIEncoding();
return ascii.GetString(mem.ToArray());
To deserialize via standerd dotnet code:
public static object DeSerializeFromXMLString(System.Type TypeToDeserialize, string xmlString)
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(xmlString);
MemoryStream mem = new MemoryStream(bytes);
System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(TypeToDeserialize);
return ser.Deserialize(mem);
Once last nice thing about a serializable settings class is because it is an object, you can use intellisense to quickly navigate to a particular setting.
Note: After you instantiated your settings container class, you should make it a static property of another static managing class (you can call it SettingsManager if you want)
This managing class allows you to access your settings from anywhere in your application (since its static) and you can also have static functions to handle the loading and saving of the class.