I am working on a personal C# project and I would like to use a nested dictionary to handle the storing of my settings.ini file values for future reading/writing to my settings.ini file. My settings.ini file consists of:
[Application]
AutoShowSetting=Log
SettingsIniDirectory=Application
LogDirectory=Application
...
I am using a two for each loops to read the information from the settings.ini file like so:
public void storeIniValues()
{
int i = 0;
string[] sectionNames = iniFile.GetSectionNames();
foreach (string section in sectionNames)
{
string[] keys = iniFile.GetKeyNames(section);
foreach (string key in keys)
{
string keyValue = iniFile.GetString(section, key, "");
i++;
}
}
}
The foreach grabs the values and places the values into their respected string variables. I would like to take the values while looping through the foreach loop and place the values into a dictionary to later read/write/update the settings.ini file. So far I created a dictionary:
static Dictionary<string, Dictionary<string, string>> iniSettings =
new Dictionary<string, Dictionary<string, string>>();
How do I access the ini values from the nested dictionary like so
iniSettings["Application"]["AutoShowSetting"] to get the corresponding value(in this case "Log")? Also, how do I add a value to the nested Dictionary while the foreach loop is looping(settingsIni[section][key] = keyValue)?
I have no idea where to begin attempting this because I have never used a nested Dictionary.
EDIT
I forgot to mention the settings.ini file will hold values to populate checkboxes, textboxes, and etc...