Beispiel #1
0
        private static void RunFileInput()
        {
            const string numbersFile = "C:\\numbers.txt";
            var          numbers     = "";

            using (var sr = new StreamReader(numbersFile))
            {
                numbers = sr.ReadToEnd();
            }

            try
            {
                var lines = numbers.Split(Environment.NewLine);
                foreach (var line in lines)
                {
                    if (BetterNumberUtilities.IsNumericFromTryParse(line))
                    {
                        Console.WriteLine($"In: {line}");
                        Console.WriteLine($"Out: {line.ToWords()}");
                    }
                    else
                    {
                        Console.WriteLine($"{line} is not a number");
                    }
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Oh no. That number is not even handled by the better method. Shame.");
            }

            _keepRunning = false;
        }
Beispiel #2
0
        private static void RunBetter()
        {
            Console.WriteLine("------------------");
            Console.WriteLine("Better Method");
            Console.WriteLine("------------------");
            Console.WriteLine("Please enter a number:");

            _stringNumber = Console.ReadLine();

            try
            {
                while (BetterNumberUtilities.IsNumericFromTryParse(_stringNumber))
                {
                    Console.WriteLine(_stringNumber.ToWords());
                    Console.WriteLine("Please enter another number:");
                    _stringNumber = Console.ReadLine();
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Oh no. That number is not even handled by the better method. Shame.");
            }

            _keepRunning = false;
        }