I have interesting question. According to MSDN yield syntax:
yield return <expression>; // yield some value
yield break; // exiting from iterator
Why not just:
yield <expression>; // yield some value
return; // exiting from iterator
To me second form would be less verbose and still would have same meaning as first.
So the question is – Why first form was chosen by .NET designers ? What reasons may caused this ? What potential design problems second form has ?
Here’s one possibility: it would create a technical ambiguity (remember that
yieldis a contextual keyword, not a reserved keyword)… Unlikely, but:Then
Is actually a variable declaration. With the “yield return x;”, that is only valid one way.
No idea if this is true. Just a thought.