I'm currently developing a C# Tool for my company and I just got stuck working with the dictionary.
It's about reading from an .ini
file and saving the Sections and Keys to a Dictionary<string, string>
.
What I have here:
public void GetDataToDictrionary()
{
FileIniDataParser fileParser = new FileIniDataParser();
IniData data = fileParser.ReadFile("config.ini");
Dictionary<string, string> newDictionary = new Dictionary<string, string>();
foreach (SectionData section in data.Sections)
{
foreach (KeyData key in section.Keys)
newDictionary.Add(section.SectionName.ToString(), key.Value.ToString());
}
}
I know that the newDictionary.Add
function will throw some Argument exception.
If I write it directly from the .Ini File to the Console with:
foreach (SectionData section in data.Sections)
{
Console.WriteLine("[" + section.SectionName + "]");
foreach (KeyData key in section.Keys)
Console.WriteLine(key.KeyName + " = " + key.Value);`
}
It will output as:
`*[NewCCReduced1]
name=NewCCReduced1.cone.bombardier.com
ipaddress=10.167.21.11
macaddress=000bab46edeb*`
Which is totally fine as the .ini
File has this structure:
`*[NewCCReduced1] /Sectionname
name=NewCCReduced1.cone.bombardier.com /KeyName = KeyValue
ipaddress=10.167.21.11 /KeyName = KeyValue
macaddress=000bab46edeb /KeyName = KeyValue
/Comment*`
Has somebody of you maybe an idea how I could solve the problem like saving all there variables to my Dictionary?