I have two lists that are of the same length, is it possible to loop through these two lists at once?
I am looking for the correct syntax to do the below
I recommend using plain old for loop, but you should consider different array lengths. So
for(int i=0; i
can turn into
for(int i = 0; i < Math.Min(ListA.Length, ListB.Lenght); i++)
{
Console.WriteLine(ListA[i].ToString() + ", " + ListB[i].ToString());
}
or even into
for(int i = 0; i < Math.Max(ListA.Length, ListB.Lenght); i++)
{
string valueA = i < ListA.Length ? listA[i].ToString() : "";
string valueB = i < ListB.Length ? listB[i].ToString() : "";
Console.WriteLine(valueA+ ", " + valueB);
}