Advertisement
SnowPhoenix347

4.3

Nov 4th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1. using System;
  2. using System.Runtime.InteropServices;
  3.  
  4. namespace FifthProject
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.            
  11.             int userNumber = ConvertToInt();
  12.             Console.WriteLine(userNumber);
  13.         }
  14.         static int ConvertToInt()
  15.         {
  16.             Console.WriteLine("Введите число");
  17.             int output;
  18.             bool enterIsCorrect = false;
  19.             do
  20.             {
  21.                 string input = Console.ReadLine();
  22.                 enterIsCorrect = int.TryParse(input, out output);
  23.                 if (!enterIsCorrect)
  24.                 {
  25.                     Console.WriteLine("Ложное значение. Повторите попытку");
  26.                 }
  27.             } while (!enterIsCorrect);
  28.  
  29.             return output;
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement