Try this:
private void WriteParam(string section, string key, string value)
{
List<string> lines = new List<string>(File.ReadAllLines(@"D:\InitiatorVals.ini"));
int index = lines.IndexOf(section);
if (index > -1)
{
bool valueChanged = false;
while (!lines[++index].StartsWith("["))
{
if (lines[index].StartsWith(String.Concat(key, "=")))
{
lines[index] = String.Format("{0}={1}", key, value);
valueChanged = true;
break;
}
}
if (!valueChanged)
{
}
}
else
{
}
File.WriteAllLines(@"D:\InitiatorVals.ini", lines);
}
At
lines[++index]
, it is necessary that you add the
++
before the variable name, because that makes sure that the return value of the operation is the value after the variable is incremented.