Monday, December 7, 2015

Check string is number or not in C#

Int.TryParse() method converts string into integer and if this conversion is not possible then it will return false means your inputted string is not number

string number = "1234";
int a = 0;
bool isNumber = int.TryParse(number, out a);

if (isNumber == true)
{
            //string is valid number
}
else
{
           //Given string is not a number
}