/// <summary> /// Method for reading Console Key. /// </summary> /// <param name="prompt">The prompt.</param> /// <returns>A key.</returns> public static ConsoleKey ReadKey(string prompt) { Console.ForegroundColor = ConsoleColor.Green; Output.DisplayPrompt(prompt); Console.ResetColor(); return(Console.ReadKey().Key); }
/// <summary> /// Method for reading an integer. /// </summary> /// <param name="min">Min value.</param> /// <param name="max">Max value.</param> /// <returns>An integer.</returns> public static int ReadInt(int min, int max) { var value = ReadInt(); while (value < min || value > max) { Output.DisplayPrompt("Please enter an integer between {0} and {1} (inclusive):", min, max); value = ReadInt(); } return(value); }
/// <summary> /// Method for reading an integer. /// </summary> /// <returns>An integer.</returns> public static int ReadInt() { var input = Console.ReadLine(); int value; while (!int.TryParse(input, out value)) { Output.DisplayPrompt("Please enter an integer:"); input = Console.ReadLine(); } return(value); }
/// <summary> /// Method for reading a string. /// </summary> /// <param name="prompt">The prompt.</param> /// <returns>A string.</returns> public static string ReadString(string prompt) { Output.DisplayPrompt(prompt); return(Console.ReadLine()); }
/// <summary> /// Method for reading an integer. /// </summary> /// <param name="prompt">The prompt.</param> /// <param name="min">Min value.</param> /// <param name="max">Max value.</param> /// <returns>An integer.</returns> public static int ReadInt(string prompt, int min, int max) { Output.DisplayPrompt(prompt); return(ReadInt(min, max)); }