Using foreach loop to iterate through two lists

后端 未结 5 1748
攒了一身酷
攒了一身酷 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:34

    If you want to simultaneously iterate over two Lists of the same length (specially in the scenarios like comparing two list in testing), I think for loop makes more sense:

    for (int i = 0; i < list1.Count; i++) {
        if (list1[i] == list2[i]) {
            // Do something
        }
    }
    

提交回复
热议问题