Advertisement
Montagne94

21. ReadInt

Sep 23rd, 2020 (edited)
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System;
  2. namespace ConsoleApp1
  3. {
  4.     class Program
  5.     {
  6.         static void Main(string[] args)
  7.         {
  8.             int convertResult = ConvertValue();
  9.             Console.WriteLine($"Ваше значение {convertResult} успешно конвертировано");
  10.         }
  11.  
  12.         static int ConvertValue()
  13.         {
  14.             bool convertTrue = false;
  15.             string userValue;
  16.             int convertResult = 0;
  17.  
  18.             while (!convertTrue)
  19.             {
  20.                 Console.WriteLine("Введите значение");
  21.                 userValue = Console.ReadLine();
  22.  
  23.                 convertTrue = int.TryParse(userValue, out convertResult);
  24.                 Console.Clear();
  25.             }
  26.             return convertResult;
  27.         }
  28.  
  29.  
  30.  
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement