GetEnumerator() public méthode

public GetEnumerator ( ) : IEnumerator
Résultat IEnumerator
Exemple #1
0
        static void Main(string[] args)
        {
            GenericList <String> stringList = new GenericList <string>();

            stringList.Add("abc");
            stringList.Add("def");
            stringList.Add("ghi");
            stringList.Add("jkl");
            stringList.Add("mno");
            stringList.Add("pqr");

            // foreach
            foreach (string value in stringList)
            {
                Console.WriteLine(value);
            }

            // foreach without the syntax sugar
            IEnumerator <string> enumerator = stringList.GetEnumerator();

            while (enumerator.MoveNext())
            {
                string value = (string)enumerator.Current;
                Console.WriteLine(value);
            }

            Console.ReadLine();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var listOfIntegers = new Integerlist(5);

            ListExample(listOfIntegers);

            /*
             * var polje = new Integerlist(4);
             * polje.Add(3);
             * polje.Add(4);
             * polje.Add(7);
             * polje.Add(6);
             * polje.Remove(7);
             * polje.Add(2);
             * polje.Add(8);
             * polje.Remove(4);
             *
             * Console.WriteLine(polje.Contains(1));  //false
             * polje.GetElement(4);       //0
             * Console.WriteLine("\nNumber of elements" + " " + polje.Count); //4
             * polje.print();  //3 6 2 8 0 0 0 0
             * Console.WriteLine(polje.Clear()); //True
             *
             */
            IGenericList <string> stringList = new GenericList <string>();

            stringList.Add(" Hello ");
            stringList.Add(" World ");
            stringList.Add("!");

            foreach (string value in stringList)
            {
                Console.WriteLine(value);
            }

            IEnumerator <string> enumerator = stringList.GetEnumerator();

            while (enumerator.MoveNext())
            {
                string value = (string)enumerator.Current;
                Console.WriteLine(value);
            }
            Console.ReadLine();
        }
Exemple #3
0
 public IEnumerator <T> GetEnumerator()
 {
     if (ProxyGetEnumerator != null)
     {
         return(ProxyGetEnumerator());
     }
     else if (GenericList != null)
     {
         return(GenericList.GetEnumerator());
     }
     else if (NonGenericList != null)
     {
         return(NonGenericList.Cast <T>().GetEnumerator());
     }
     else
     {
         throw new NotImplementedException();
     }
 }
        public static void Main(string[] args)
        {
            IGenericList<string> stringList = new GenericList<string>();
            stringList.Add("Hello");
            stringList.Add("World");
            stringList.Add("!");
            foreach (var VARIABLE in stringList)
            {
                Console.WriteLine(VARIABLE);
            }
            var enumerator = stringList.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var value = enumerator.Current;
                Console.WriteLine(value);
            }
            Console.ReadLine();
        }