How to iterate through two collections of the same length using a single foreach

后端 未结 6 1209
情深已故
情深已故 2020-12-29 22:23

I know this question has been asked many times before but I tried out the answers and they don\'t seem to work.

I have two lists of the same length but not the same

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-29 22:42

    Instead of a foreach, why not use a for()? for example...

    int length = list1.length;
    for(int i = 0; i < length; i++)
    {
        // do stuff with list1[i] and list2[i] here.
    }
    

提交回复
热议问题