Anybody know why the Output of this program is like this?(using iterator in c#)
Posted
by Babu
on Stack Overflow
See other posts from Stack Overflow
or by Babu
Published on 2009-11-19T13:07:06Z
Indexed on
2010/05/15
23:00 UTC
Read the original article
Hit count: 338
using System;
using System.Collections;
namespace Iterator_test
{
class Day
{
int days_idx = -1;
private String[] days = { "mon", "tue", "wed","thu","fri","sat","sun" };
public IEnumerable getdays()
{
days_idx++;
yield return days[days_idx];
}
}
class Program
{
static void Main(string[] args)
{
Day d = new Day();
foreach (string day in d.getdays())
{
Console.WriteLine(day);
}
}
}
}
Actually the output should be,
mon
tue
wed
thu
fri
sat
sun
but its printing only "mon" as,
mon
What will be the reason?
© Stack Overflow or respective owner