Advertisement
areyesram

ValuePass

Jul 26th, 2020
1,469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ValuePass
  4. {
  5.     internal class Program
  6.     {
  7.         private static void Main()
  8.         {
  9.             Test1();
  10.             Test2();
  11.         }
  12.  
  13.         private static void Test1()
  14.         {
  15.             try
  16.             {
  17.                 int numero = int.Parse("123");
  18.                 Console.WriteLine("El número vale {0}", numero);
  19.             }
  20.             catch (Exception)
  21.             {
  22.                 Console.WriteLine("No es un número válido");
  23.             }
  24.         }
  25.  
  26.         private static void Test2()
  27.         {
  28.             int numero;
  29.             if (int.TryParse("123", out numero))
  30.             {
  31.                 Console.WriteLine("El número vale {0}", numero);
  32.             }
  33.             else
  34.             {
  35.                 Console.WriteLine("No es un número válido");
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement