Using foreach loop to iterate through two lists

后端 未结 5 1746
攒了一身酷
攒了一身酷 2021-02-12 15:39

I have two lists

List a = new List();
List b = new List();


Now i want to iterate throug

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-12 16:36

    This is another way you could do it:

    for (int i = 0; i < (a.Count > b.Count ? a.Count : b.Count); i++)
    {
        object objA, objB;
        if (i < a.Count) objA = a[i];
        if (i < b.Count) objB = b[i];
    
        // Do stuff
    }
    

提交回复
热议问题