How to Check if string is valid Number in C#?

Updated on     Kisan Patel

Use the static TryParse method of any of the numeric types.

For example, to determine whether a string contains a double, use the following method:

string str = "10.5";
double result = 0;
if (double.TryParse(str,
     out result))
    // Is a double!

Here is another Example:

int n;
bool isNumeric = int.TryParse("123", out n);


Leave a Reply