Marco

Marco

  • NA
  • 59
  • 0

yield

Oct 28 2007 8:26 AM

Hello,
this below work but it isn't what I'd like; GetNumber() return an Enumerable and at the moment I'd like that it return an IEnumerator  ...
Can I have an help, please?


class Number {
 List<Number> number;
 Number (){number=new List<Number>(); }
 public void insert(int n) { number.Add(n); }

public static IEnumerable<int> GetNumber() {
            IEnumerator ir = number.GetEnumerator();
            for (; ir.MoveNext(); ){

                 if (ir.Current.isPair() )

                        yield return ir.Current;

            }

         }
}

class Program
{
        static void Main(string[] args)
        {
        Number n = new Number();
        n.insert (10);
n.insert (20); .....30, 40...50
        foreach (int i in GetNumber() )
                Console.WriteLine("Number {0}", i);
        }
}


Answers (3)