Beispiel #1
0
        /// <summary>
        /// Reads the string.
        /// </summary>
        /// <param name="prompt"> The string being asked for.</param>
        /// <returns>Returns the alphabetic value.</returns>
        public static string ReadAlphabeticValue(string prompt)
        {
            string result = null;

            bool found = false;

            while (!found)
            {
                result = ConsoleUtil.ReadStringValue(prompt);

                if (Regex.IsMatch(result, @"^[a-zA-Z ]+$"))
                {
                    found = true;
                }
                else
                {
                    Console.WriteLine(prompt + " must contain only letters or spaces.");
                }
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Reads the value of the double.
        /// </summary>
        /// <param name="prompt"> The value being ask for.</param>
        /// <returns> The double from the string.</returns>
        public static double ReadDoubleValue(string prompt)
        {
            double result = 0;

            string stringValue = result.ToString();

            bool found = false;

            while (!found)
            {
                stringValue = ConsoleUtil.ReadStringValue(prompt);

                if (double.TryParse(stringValue, out result))
                {
                    found = true;
                }
                else
                {
                    Console.WriteLine(prompt + " must be either a whole number or a decimal number.");
                }
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Reads the value of the int.
        /// </summary>
        /// <param name="prompt"> The value being ask for.</param>
        /// <returns> The int from the string.</returns>
        public static int ReadIntValue(string prompt)
        {
            int result = 0;

            string stringValue = result.ToString();

            bool found = false;

            while (!found)
            {
                stringValue = ConsoleUtil.ReadStringValue(prompt);

                if (int.TryParse(stringValue, out result))
                {
                    found = true;
                }
                else
                {
                    Console.WriteLine(prompt + " must be a whole number.");
                }
            }

            return(result);
        }