- yield can be used to return partially.
- yield maintains the state of the object
void Main()
{
foreach(int i in GetDivideByTwo())
{
Console.WriteLine(i);
}
}
static System.Collections.Generic.IEnumerable
{
for (int i = 0; i < 100; i++)
yield return i/2;
}
Here is couple of good links
http://stackoverflow.com/questions/1088442/what-is-the-purpose-advantage-of-using-yield-return-iterators-in-c/1088452#1088452
http://stackoverflow.com/questions/3969963/when-not-to-use-yield-return/3970171#3970171
No comments:
Post a Comment