I wouldn't suggest using LINQ here as there is really no reason to and you don't gain anything by using LINQ, but simply using a normal for
loop and increasing your counting variable by two in each iteration:
var result = new List<KeyValuePair<string, string>>();
for (int index = 1; index < input.Count; index += 2)
{
result.Add(new KeyValuePair<string, string>(input[index - 1], input[index]));
}
Note that I'm starting my index with 1
so I don't run into an exception for accessing an invalid index in case the number of items in input
is odd, i.e. if input
ends with a "half pair" of values.