//If MoveNext passes the end of the collection, the enumerator is positioned after the last element in the collection and MoveNext returns false. When the enumerator is at this position, subsequent calls to MoveNext also return false. If the last call to MoveNext returned false, calling Current throws an exception.
 public bool MoveNext()
 {
     if (_numbersLeft == 0)
     {
         return(false);
     }
     _integers.Next();
     _numbersLeft--;
     return(true);
 }
Exemple #2
0
        private static void UseCircularIntList()
        {
            CircularIntList list = new CircularIntList();

            Console.WriteLine(list.Current().ToString());

            list.Add(3);
            Console.WriteLine(list.Current());

            list.Add(2);
            list.Add(1);

            Console.WriteLine(list.Current());
            list.Next();

            Console.WriteLine(list.Current());
            list.Next();

            Console.WriteLine(list.Current());
            list.Next();

            Console.WriteLine(list.Current());
            list.Next();

            Console.WriteLine(list.Current());
            list.Next();

            Console.WriteLine(list.Current());
            list.Next();


            Console.WriteLine("=== Testing foreach ===");
            foreach (int i in list)
            {
                Console.WriteLine(i);
            }
        }