C
cody
currently, foreach takes a IEnumerable as parameter, so we can do:
foreach (int i in array){}
what about an additional form of foreach that takes an IEnumerator as
parameter, so we can do:
foreach (int i in array.SkipIterator(2)) // get every 2nd item
or
foreach (int i in array.RangeIterator(2, 10)) // iterates items from 2 to 10
or
foreach (int i in array.ReverseIterator()) // iterates through items in
reverse order
or
foreach (int i in array.SafeIterator(typeof(int))) // iterates through all
items that are != null and are of type int
What do you think? I always wanted such a thing since foreach with iterators
are much better readable as a for loops and the intend is much clearer.
foreach (int i in array){}
what about an additional form of foreach that takes an IEnumerator as
parameter, so we can do:
foreach (int i in array.SkipIterator(2)) // get every 2nd item
or
foreach (int i in array.RangeIterator(2, 10)) // iterates items from 2 to 10
or
foreach (int i in array.ReverseIterator()) // iterates through items in
reverse order
or
foreach (int i in array.SafeIterator(typeof(int))) // iterates through all
items that are != null and are of type int
What do you think? I always wanted such a thing since foreach with iterators
are much better readable as a for loops and the intend is much clearer.