Garloon

4.3

Sep 2nd, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace CSLight2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int number;
  14.             bool correct = false;
  15.  
  16.             while(correct == false)
  17.             {
  18.                 Console.Write("Ведите данные: ");
  19.                 string userInput = Console.ReadLine();
  20.                
  21.                 if (int.TryParse(userInput, out number))
  22.                 {
  23.                     Console.ForegroundColor = ConsoleColor.Green;
  24.                     Console.WriteLine("\nВы ввели число: {0}", number);
  25.                     Console.ResetColor();
  26.                     correct = true;
  27.                 }
  28.                 else
  29.                 {
  30.                     Console.ForegroundColor = ConsoleColor.Red;
  31.                     Console.WriteLine("\nВы ввели не число!");
  32.                     Console.ResetColor();
  33.                     Console.ReadKey();
  34.                     Console.Clear();
  35.                 }
  36.             }
  37.             Console.ReadKey();
  38.  
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment