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 2:03 AM by Fortuitus


Fortuitus wrote Jul 2, 2009 at 4:06 PM

Great catch!

wrote Jul 2, 2009 at 4:09 PM

wrote Sep 21, 2009 at 2:03 AM

wrote Feb 13, 2013 at 9:27 PM

wrote May 16, 2013 at 2:53 AM