SHOW:
|
|
- or go back to the newest paste.
1 | using System; | |
2 | ||
3 | namespace C_sharp_Light | |
4 | { | |
5 | class Program | |
6 | { | |
7 | static void Main(string[] args) | |
8 | { | |
9 | int number = 0; | |
10 | - | number = ReadAndConvertToInt(); |
10 | + | number = ReadInt(); |
11 | Console.WriteLine($"Ваше число - {number}"); | |
12 | Console.ReadKey(); | |
13 | } | |
14 | - | static int ReadAndConvertToInt() |
14 | + | static int ReadInt() |
15 | { | |
16 | string value; | |
17 | int result; | |
18 | ||
19 | while (true) | |
20 | { | |
21 | Console.Write("Введите число: "); | |
22 | value = Console.ReadLine(); | |
23 | if (int.TryParse(value, out result)) | |
24 | { | |
25 | Console.WriteLine("Конвертация прошла успешно"); | |
26 | ||
27 | Console.ReadKey(); | |
28 | Console.Clear(); | |
29 | return result; | |
30 | } | |
31 | else | |
32 | { | |
33 | Console.WriteLine("Конвертация прошла не успешно. Попробуйте ещё раз."); | |
34 | Console.ReadKey(); | |
35 | Console.Clear(); | |
36 | } | |
37 | ||
38 | } | |
39 | } | |
40 | } | |
41 | } |