Is it possible to iterate over two IEnumerable objects at the same time?

前端 未结 7 1952
醉梦人生
醉梦人生 2020-12-19 12:55

If I have a List(Of x) and a List(Of y) is it possible to iterate over both at the same time?

Something like

for each _x as X, _y as Y in List(of x         


        
7条回答
  •  佛祖请我去吃肉
    2020-12-19 13:28

    You would have to access the enumerators manually. In C#:

    using (IEnumerator xe = List1.GetEnumerator())
    using (IEnumerator ye = List2.GetEnumerator()) {
        while (xe.MoveNext() && ye.MoveNext()) {
             if (xe.Current == ye.Current) {
                 // do something
             }
        }
    }
    

提交回复
热议问题