static void Main(string[] args)
        {
            try
            {
                int value = int.Parse(Console.ReadLine());
                if (value < 1)
                {
                    throw new ArgumentException();
                }

                MyInts      myInts     = new MyInts();
                IEnumerator enumerator = myInts.MyEnumerator(value);

                IterateThroughEnumeratorWithoutUsingForeach(enumerator);
                Console.WriteLine();
                IterateThroughEnumeratorWithoutUsingForeach(enumerator);
            }
            catch (ArgumentException)
            {
                Console.WriteLine("error");
            }
            catch (Exception)
            {
                Console.WriteLine("error");
            }
            Console.ReadLine();
        }
        static void IterateThroughEnumeratorWithoutUsingForeach(IEnumerator enumerator)
        {
            string output = "";
            MyInts Ints   = (MyInts)enumerator;

            while (Ints.MoveNext() == true)
            {
                output += Ints.number * Ints.number + " ";
            }
            Console.Write(output.Remove(output.Length - 1));
        }
Beispiel #3
0
 static void Main(string[] args)
 {
     try
     {
         int         num        = ParseToInt();
         MyInts      myInts     = new MyInts(num);
         IEnumerator enumerator = myInts.MyEnumerator(num);
         Iterator(enumerator, num);
         Console.WriteLine();
         Iterator(enumerator, num);
     }
     catch (ArgumentException)
     {
         Console.WriteLine("error");
     }
 }
        static void Main(string[] args)
        {
            try
            {
                int value =
                    MyInts myInts = new MyInts();
                IEnumerator enumerator = myInts.MyEnumerator(value);

                IterateThroughEnumeratorWithoutUsingForeach(enumerator);
                Console.WriteLine();
                IterateThroughEnumeratorWithoutUsingForeach(enumerator);
            }
            catch (ArgumentException)
            {
                Console.WriteLine("error");
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            try
            {
                int value = 0;
                if (!int.TryParse(Console.ReadLine(), out value) || value <= 0)
                {
                    throw new ArgumentException();
                }
                MyInts      myInts     = new MyInts();
                IEnumerator enumerator = myInts.GetIntEnumerator(value);

                IterateThroughEnumeratorWithoutUsingForeach(enumerator);
                Console.WriteLine();
                IterateThroughEnumeratorWithoutUsingForeach(enumerator);
            }
            catch (ArgumentException)
            {
                Console.WriteLine("error");
            }
        }
        static void Main(string[] args)
        {
            try
            {
                string input = Console.ReadLine();
                if (!int.TryParse(input, out _))
                {
                    throw new ArgumentException();
                }
                int         value      = int.Parse(input);
                MyInts      myInts     = new MyInts();
                IEnumerator enumerator = myInts.MyEnumerator(value);

                IterateThroughEnumeratorWithoutUsingForeach(enumerator);
                Console.WriteLine();
                IterateThroughEnumeratorWithoutUsingForeach(enumerator);
            }
            catch (ArgumentException)
            {
                Console.WriteLine("error");
            }
        }
        static void Main(string[] args)
        {
            try
            {
                if (int.TryParse(Console.ReadLine(), out int value) && value > 0)
                {
                    MyInts      myInts     = new MyInts();
                    IEnumerator enumerator = myInts.MyEnumerator(value);

                    IterateThroughEnumeratorWithoutUsingForeach(enumerator);
                    Console.WriteLine();
                    IterateThroughEnumeratorWithoutUsingForeach(enumerator);
                }
                else
                {
                    throw new ArgumentException();
                }
            }
            catch (ArgumentException)
            {
                Console.WriteLine("error");
            }
            Console.ReadLine();
        }