Tuesday, April 8, 2008

Iterator yield return sample code

using System.Collections.Generic;

protected void Page_Load(object sender, EventArgs e)
{
foreach (var v in OneTwoThree())
{
Response.Write(v);
}
}
private IEnumerable OneTwoThree()
{
Response.Write("return 1");
yield return 1;
Response.Write("return 2");
yield return 2;
Response.Write("return 3");
yield return 3;
}

No comments: