I have two lists
List<object> a = new List<object>(); List<object> b = new List<object>();
Now i want to iterate through the elements of both list. I could do that by writing a foreach loop for each list. But is it also possible to do something like that?
foreach(object o in a, b) { o.DoSomething(); }
It would also be nice if something like that would be possible:
foreach (object o in a && b) { o.DoSomething(); }
Use the izip() Function to Iterate Over Two Lists in Python It iterates over the lists until the smallest of them gets exhausted. It then zips or maps the elements of both lists together and returns an iterator object. It returns the elements of both lists mapped together according to their index.
Using the CodeThe ForEach method of the List<T> (not IList<T> ) executes an operation for every object which is stored in the list. Normally it contains code to either read or modify every object which is in the list or to do something with list itself for every object.
To use forEach to loop through two arrays at the same time in JavaScript, we can use the index parameter of the forEach callback to get the element with the same index from the 2nd array. const n = [1, 2, 3, 5, 7, 8, 9, 11, 12, 13]; const m = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; n.
foreach(object o in a.Concat(b)) { o.DoSomething(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With