Lack of IsNumeric function in C#
Posted
by Michael Kniskern
on Stack Overflow
See other posts from Stack Overflow
or by Michael Kniskern
Published on 2010-05-26T22:16:18Z
Indexed on
2010/05/26
22:21 UTC
Read the original article
Hit count: 327
One thing that has bothered me about C# since its release was the lack of a generic IsNumeric function. I know it is difficult to generate a one-stop solution to detrmine if a value is numeric.
I have used the following solution in the past, but it is not the best practice because I am generating an exception to determine if the value is IsNumeric:
public bool IsNumeric(string input)
{
try
{
int.Parse(input);
return true;
}
catch
{
return false;
}
}
Is this still the best way to approach this problem or is there a more efficient way to determine if a value is numeric in C#?
© Stack Overflow or respective owner