C# equivalent of NaN or IsNumeric

Posted by johnc on Stack Overflow See other posts from Stack Overflow or by johnc
Published on 2009-01-13T03:32:07Z Indexed on 2010/05/16 22:50 UTC
Read the original article Hit count: 253

Filed under:
|

This seems like a fairly simple question, and I'm surprised not to have required it before.

What is the most efficient way of testing a string input is a numeric (or conversely Not A Number).

I guess I can do a Double.Parse or a regex (see below)

public static bool IsNumeric(this string value)
{
    return Regex.IsMatch(value, "^\\d+$");
}

but I was wondering if there was a implemented way to do it, such as javascript's NaN() or IsNumeric() (was that VB, I can't remember).

© Stack Overflow or respective owner

Related posts about c#

Related posts about parsing