Пример #1
0
        public static int ReadSingleDigitNumberInstant(int max, bool showMessageIfInvalid = true, bool intercept = false)
        {
            char input = Console.ReadKey(true).KeyChar;

            if (input.IsNumeric())
            {
                if ((input - 48) <= max)
                {
                    if (!intercept)
                    {
                        Console.WriteLine(input);
                    }
                    return(input - 48);
                }
                else if (showMessageIfInvalid)
                {
                    ConsoleWrite.WriteLinesColored(ConsoleColor.Red, "Invalid input", TOO_HIGH);
                }
            }
            else if (showMessageIfInvalid)
            {
                ConsoleWrite.WriteLinesColored(ConsoleColor.Red, "Invalid input", "Not a number");
            }

            return(ReadSingleDigitNumberInstant(max, showMessageIfInvalid, intercept));
        }
Пример #2
0
 public static short ReadInt16(bool showMessageIfInvalid = true)
 {
     if (short.TryParse(Console.ReadLine(), out short result))
     {
         return(result);
     }
     else
     {
         if (showMessageIfInvalid)
         {
             ConsoleWrite.WriteLinesColored(ConsoleColor.Red, "Invalid input", "Not Int16");
         }
         return(ReadInt16(showMessageIfInvalid));
     }
 }
Пример #3
0
        public static string ReadNonWhitespace(bool showMessageIfInvalid = true)
        {
            string input = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(input))
            {
                if (showMessageIfInvalid)
                {
                    ConsoleWrite.WriteLinesColored(ConsoleColor.Red, "Invalid input", "Input was null of whitespace");
                }
                return(ReadNonWhitespace(showMessageIfInvalid));
            }
            else
            {
                return(input);
            }
        }