Use TryParse from int : int parse « Data Type « C# / CSharp Tutorial






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());
 }
}
Please enter an integer and press Enter
12
You entered 12








2.9.int parse
2.9.1.Int Parsing
2.9.2.Use TryParse from int