Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp3
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- int userInput = 0;
- tryParse(ref userInput);
- Console.WriteLine("Вы ввели число: " + userInput);
- Console.ReadKey();
- }
- public static int tryParse(ref int userInput)
- {
- while (true)
- {
- Console.Write("Введите число: ");
- bool parse = int.TryParse(Console.ReadLine(), out userInput);
- Console.Clear();
- if (parse)
- {
- return userInput;
- }
- else
- {
- Console.WriteLine("Что-то пошло не так.");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement