Esempio n. 1
0
        public static void Main(string[] args)
        {
            try
            {
                Console.SetBufferSize(200, 300);                   // make sure buffer is bigger than window so you can scroll to left.
                Console.WindowWidth = 200;
            }
            catch (System.IO.IOException)
            {
                /* The above lines will fail to execute in UnitTest mode. */
            }

            Console.WriteLine("Enter a max number of primes:");

            while (true)
            {
                string lineValue = Console.ReadLine();
                int    maxPrimesToGenerate;
                if (int.TryParse(lineValue, out maxPrimesToGenerate) && isValidNumber(maxPrimesToGenerate))
                {
                    Console.WriteLine("You Entered:" + maxPrimesToGenerate);

                    var primeNumbers = PrimeNumbersHelper.Generate(maxPrimesToGenerate);
                    TablePrinter.Print(primeNumbers);
                    break;
                }
                else
                {
                    if (lineValue == "exit")
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Please specify a numceric value which is greater or equal to 1.");
                        break;
                    }
                }
            }

            Console.WriteLine("Press return to close application.");
            Console.ReadLine();
        }
        /// <summary>
        /// Print Prime Numbers to Console
        /// </summary>
        /// <param name="primeNumbers"></param>
        public static void Print(List <int> primeNumbers)
        {
            var array = PrimeNumbersHelper.CreateArrayForPrimeNumbers(primeNumbers);

            PrintTable(array);
        }