Alex Rivera | Logout

yield return works only for IEnumerable<T>?

Asked 2009-07-01T19:46:34.230
38

Can I use yield return when the return type is an IGrouping<TKey, TElement> or an IDictionary<TKey, TValue>?

Edit
Report

2 Answers

2

No, because an iterator block is simply a state machine built on your behalf by the compiler. This feature allows you to "yield" and item as a portion of a sequence.

If the return type was other than IEnumerable<T> (like IDictionary for example) the compiler would have to generate methods to implement that interface and at that point it wouldn't make much sense because you would be working with a collection rather than a sequence.

answered 2009-07-01T19:49:52.443
-1

nope, just ienumerable :-)

answered 2009-07-01T19:47:49.187

Your Answer