SHARE
TWEET

Untitled

a guest Jan 24th, 2020 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public static int PromptInt(string message)
  2.     {
  3.       Console.Write(message);
  4.       var input = Console.ReadLine();
  5.  
  6.       if (String.IsNullOrEmpty(input)) return 0;
  7.  
  8.       var isNumber = int.TryParse(input, out var age);
  9.       if (!isNumber) return -1;
  10.       if (age > 200 || age <= 0) return -1;
  11.  
  12.       if (age == -1)
  13.       {
  14.         Console.WriteLine(age + " is not a valid number.");
  15.       }
  16.       return age;
  17.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top