I am trying to get the following code to compile but am getting errors in VS2008. Anyone can tell me where I am going wrong?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace dummy
{
public class NaturalNumbersSequence : IEnumerable<int>
{
public IEnumerator<int> GetEnumerator()
{
for (int i = 1; i <= 1000; i++)
yield return i;
}
IEnumerator IEnumerable.GetEnumerator()
{
for (int i = 1; i <= 1000; i++)
yield return i;
}
}
class Program
{
static void Main(string[] args)
{
foreach (int i in new NaturalNumbersSequence())
Console.WriteLine(i);
}
}
}