Given a list of strings:
"A"
"B"
"C"
"D"
I will expect to get a list of lists of 2 items each one but with the second item repeated:
"A", "B"
"B", "C"
"C", "D"
What I am trying is the next any possible better solution?
//result = List<string> {"A","B","C","D"}
List<List<string>> obList = new List<List<string>>();
List<string> tst = new List<string>(2);
foreach (var s in result)
{
tst.Add(s);
if (tst.Count == 2)
{
obList.Add(tst);
tst = new List<string> { s };
}
}