Advertisement
TargeTPoweR

int.TryParse()

Mar 28th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 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 Tasks
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Console.WriteLine("Введите число");
  14. Convert();
  15. }
  16. static int Convert()
  17. {
  18. while (true)
  19. {
  20. string txt = Console.ReadLine();
  21. int.TryParse(txt, out int result);
  22.  
  23. if (result == 0)
  24. {
  25. Console.WriteLine("Вы ввели не число!!!");
  26. }
  27. else
  28. {
  29. Console.WriteLine("Вы ввели число: " + result);
  30. return result;
  31. }
  32. }
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement