Esempio n. 1
0
        public void Exercise8()
        {
            ActualExercises obj = new ActualExercises();

            for (int i = 2; i <= 5; i++)
            {
                do
                {
                    MethodInfo method = obj.GetType().GetMethod($"Exercise{i}");
                    method.Invoke(obj, null);
wrongInput:
                    Console.Write("Would you like to continue (y/n)? ");
                    char response = char.ToLower(Console.ReadKey().KeyChar);
                    Console.WriteLine("");
                    if (response == 'y')
                    {
                        continue;
                    }
                    else if (response == 'n')
                    {
                        Console.WriteLine("Goodbye!");
                        break;
                    }
                    else
                    {
                        Console.WriteLine("This input is not valid. Please try again.");
                        goto wrongInput;
                    }
                } while (true);
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            while (true)
            {
                ActualExercises obj = new ActualExercises();
askExerciseNumber:
                Console.Write("What exercise # would you like to go to? ");
                int response = -23;
                if (!int.TryParse(Console.ReadLine(), out response) || response < -22 || response > 78)
                {
                    goto askExerciseNumber;
                }
                if (response == 0)
                {
                    break;
                }
                else if (response > 0 && response < 26)
                {
                    MethodInfo method = obj.GetType().GetMethod($"Exercise{response}");
                    method.Invoke(obj, null);
                }
                else if (response > 25)
                {
                    MethodInfo method = obj.GetType().GetMethod($"Exercise{response}");
                    continueLoop((Action)Delegate.CreateDelegate(typeof(Action), obj, method));
                }
                else
                {
                    MethodInfo method = obj.GetType().GetMethod($"ExerciseB{response*-1}");
                    method.Invoke(obj, null);
                }
            }
        }