I am currently using the Dictionary method in C# to index a text file successfully, although in this case I would like to index more than one keyword (#HostName). I have tried adding an additional IF statement to the method although it doesn’t appear to work – by that I mean it seems to break the whole method.
var dictionary = new Dictionary<string, string>();
var lines = File.ReadLines("probe_settings.ini");
var ee = lines.GetEnumerator();
while (ee.MoveNext())
{
if (ee.Current.StartsWith("#PortNo"))
{
string test = ee.Current;
if (ee.MoveNext())
{
dictionary.Add(test, ee.Current);
}
else
{
throw new Exception("File not in expected format.");
}
}
}
Is it possible to index another term in this method? How could it be done?
Below is the file it is reading:
#CheckName1
HTTP Check
#PortNo1
80
#CheckName2
HTTPS Check
#PortNo2
443
or use for loop