Advertisement
Guest User

Untitled

a guest
May 26th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp3
  8. {
  9.     class MainClass
  10.     {
  11.         public static void Main(string[] args)
  12.         {
  13.             int userInput = 0;
  14.  
  15.             tryParse(ref userInput);
  16.             Console.WriteLine("Вы ввели число: " + userInput);
  17.             Console.ReadKey();
  18.         }
  19.  
  20.         public static int tryParse(ref int userInput)
  21.         {
  22.             while (true)
  23.             {
  24.                 Console.Write("Введите число: ");
  25.                 bool parse = int.TryParse(Console.ReadLine(), out userInput);
  26.                 Console.Clear();
  27.                 if (parse)
  28.                 {
  29.                     return userInput;
  30.                 }
  31.                 else
  32.                 {
  33.                     Console.WriteLine("Что-то пошло не так.");
  34.                 }
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement