예제 #1
0
 static void Main(string[] args)
 {
     try
     {
         if (!int.TryParse(Console.ReadLine(), out int value) || value < 0)
         {
             throw new ArgumentException();
         }
         MyDigits    myDigits   = new MyDigits();
         IEnumerator enumerator = myDigits.MyEnumerator(value);
         IterateThroughEnumeratorWithoutUsingForeach(enumerator);
         Console.WriteLine();
         IterateThroughEnumeratorWithoutUsingForeach(enumerator);
         Console.WriteLine();
         IterateThroughEnumeratorWithoutUsingForeach(enumerator);
     }
     catch (ArgumentException)
     {
         Console.WriteLine("error");
     }
     catch (ArithmeticException)
     {
         Console.WriteLine("ooops");
     }
 }
예제 #2
0
        static void Main(string[] args)
        {
            try
            {
                var value = int.Parse(Console.ReadLine());

                MyDigits    myDigits   = new MyDigits();
                IEnumerator enumerator = myDigits.MyEnumerator(value);

                IterateThroughEnumeratorWithoutUsingForeach(enumerator);
                Console.WriteLine();
                IterateThroughEnumeratorWithoutUsingForeach(enumerator);
                Console.WriteLine();
                IterateThroughEnumeratorWithoutUsingForeach(enumerator);
            }
            catch (ArgumentException)
            {
                Console.WriteLine("error");
            }
            catch (ArithmeticException)
            {
                Console.WriteLine("ooops");
            }
            catch (Exception)
            {
                Console.WriteLine("error");
            }
            Console.ReadKey();
        }
예제 #3
0
 static void Main(string[] args)
 {
     try
     {
         int         num        = ParseToInt();
         MyDigits    numbers    = new MyDigits(num);
         IEnumerator enumerator = numbers.MyEnumerator(num);
         Iterator(enumerator, num);
         Console.WriteLine();
         Iterator(enumerator, num);
         Console.WriteLine();
         Iterator(enumerator, num);
     }
     catch (ArgumentException)
     {
         Console.WriteLine("error");
     }
     catch (ArithmeticException)
     {
         Console.WriteLine("ooops");
     }
 }
        static void IterateThroughEnumeratorWithoutUsingForeach(IEnumerator enumerator)
        {
            MyDigits myDigits = (MyDigits)enumerator;
            string   output   = "";

            while (myDigits.MoveNext() == true)
            {
                output += Math.Pow(myDigits.number, 10) + " ";
            }
            if (MyDigits.turn == true)
            {
                string[] snums = output.Trim().Split();
                output = "";
                long[] nums = new long[snums.Length];
                for (int i = 0; i < nums.Length; i++)
                {
                    nums[i] = long.Parse(snums[nums.Length - 1 - i]);
                    output += nums[i] + " ";
                }
            }
            Console.Write(output.Remove(output.Length - 1));
        }