-
-
Save StrikerXx798/3a829eccaf671417a13d13c74f466e42 to your computer and use it in GitHub Desktop.
ДЗ: ReadInt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ConsoleApp1 | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int number = GetNumber(); | |
Console.WriteLine($"Вы ввели число: {number}"); | |
} | |
static int GetNumber() | |
{ | |
int number = int.MinValue; | |
bool isValid = false; | |
while (isValid == false) | |
{ | |
Console.Write("Введите любое число: "); | |
string input = Console.ReadLine(); | |
isValid = int.TryParse(input, out number); | |
if (!isValid) | |
{ | |
Console.WriteLine("Некорректный ввод. Пожалуйста, введите число."); | |
} | |
} | |
return number; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment