Enumerator does not reset after reaching end


An example of this problem is seen when you call the "Where" extension. e.g.
        string[] words = { "blueberry", "chimpanzee", "abacus", "banana", "banana", "apple", "cheese" };
        var m = words.Where(x => ((string)x)[0] == 'b');
        foreach (string s in m)
The code results by displaying all elements starting with 'b' however if the foreach was called again then no items will be displayed.
The same thing happends with Count, or anything else that iterates through the Enumerable.
Closed Sep 21, 2009 at 1:03 AM by Fortuitus


Fortuitus wrote Jul 2, 2009 at 3:06 PM

Great catch!

wrote Jul 2, 2009 at 3:09 PM

wrote Sep 21, 2009 at 1:03 AM

wrote Feb 13, 2013 at 8:27 PM

wrote May 16, 2013 at 1:53 AM