Thursday 17 October 2013

How to check string is number or not in C#


Method
public static Boolean IsNumeric(string stringToTest)
{
    int result;
    return int.TryParse(stringToTest, out result);
}

Usage
bool result = IsNumeric("value"); //result is false
bool result = IsNumeric("1234"); //result is true


No comments: