Advertisement
Briotar

Homework 4.1

May 14th, 2021
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Homework4
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string userInput;
  10.             bool successfulConvert = false;
  11.  
  12.             while (!successfulConvert)
  13.             {
  14.  
  15.                 Console.Write("Введите число - ");
  16.                 userInput = Console.ReadLine();
  17.  
  18.                 ConvertToInt(userInput, ref successfulConvert);
  19.             }
  20.  
  21.         }
  22.  
  23.         static void ConvertToInt(string userInput, ref bool successfulConvert)
  24.         {
  25.             int number;
  26.  
  27.             successfulConvert = Int32.TryParse(userInput, out number);
  28.             if (successfulConvert)
  29.             {
  30.                 Console.WriteLine($"Вы ввели число - {number}");
  31.             }
  32.             else
  33.             {
  34.                 Console.WriteLine("Преобразовать не вышло");
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement