Use TryParse from int : Int parse : Data Type C# Examples


C# Examples » Data Type » Int parse »

 

Use TryParse from int









    
using  System;
using  System.Collections.Generic;
using  System.Text;

class  Program
{
  static  void  Main(string[]  args)
  {
            Console.WriteLine("Please  enter  an  integer  and  press  Enter");
            int  numberEntered;
            while(!int.TryParse(Console.ReadLine(),  out  numberEntered)){
                      Console.WriteLine("Please  try  again");
            }
            Console.WriteLine("You  entered  "  +  numberEntered.ToString());
  }
}
    
   
  
   



Output

Please enter an integer and press Enter
12
You entered 12


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Type
» Int parse