Advertisement
MrVeiran

TryParse

Mar 14th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 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 ConsoleApp51
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int a = 0;
  14.             verify(ref a);
  15.             Console.WriteLine("Ура вы смогли ввести число. Вы просто умничка:)");
  16.             Console.WriteLine("Ваше писло: "+a);
  17.             Console.ReadLine();
  18.         }
  19.         static void verify(ref int a)
  20.         {
  21.             string ageRaw = string.Empty;
  22.             Console.WriteLine("Введите число!");
  23.             do
  24.             {
  25.  
  26.                 ageRaw = Console.ReadLine();
  27.                 Console.Clear();
  28.                 if (int.TryParse(ageRaw, out a))
  29.                 {
  30.                     break;
  31.                 }
  32.                 else
  33.                 {
  34.                     Console.WriteLine("Вы ввели не число. Попробуйте ещё раз!");
  35.                 }
  36.                    
  37.  
  38.             } while (true);
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement