문제

I'm a little lost in deferred execution land:

I declare an instance of an IEnumerable implementing class

var wordEnumerable = new WordEnumerable(_text);

Then I iterate over it (the first word is "Lorem")

foreach (var word in wordEnumerable)
                    Console.WriteLine(word);

.. which is written to the console.

Now right thereafter in code I do a

Console.WriteLine(wordEnumerable.Any(w => w == "Lorem"));

.. and get a False as output.

Now If I put the .Any(..) part above the foreach loop I do get a true, however the loop does start with the second word.

My expectation was that .Net creates different runtime 'contexts' for each call to an IEnumerable and its underlying IEnumerator so they don't interfere... I wouldn't want to .Reset() it by hand in order to get a proper result?

What am I missing here?

Update:

.. It is basically an IEnumerable that allows me to iterate over the words within a given string.

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top