Checks the input from command prompt and validates if it is number or not - CSharp System

CSharp examples for System:DateTime Format

Description

Checks the input from command prompt and validates if it is number or not

Demo Code


using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*w  ww . j a  v  a2s.co  m*/

public class Main{
        /// <summary>
        /// Checks the input from command prompt and validates if it is number or not
        /// </summary>
        /// <param name="a"></param>
        public static void CheckInput(out int a)
        {
            while (true)
            {
                string input = Console.ReadLine();
                if (Int32.TryParse(input, out a)) { break; }
                else Console.Write("Enter a valid number:");
            }
        }
}

Related Tutorials