I'm trying to check if an object is a number or not.
The IsNumeric function below works most of the time except when I pass a value of "NaN"
So I have this:
private void button1_Click(object sender, EventArgs e)
{
object obj = "NaN";
bool check = IsNumeric(obj);
if (check)
{
MessageBox.Show(obj.ToString() + " is a number");
}
}
public bool IsNumeric(object Expression)
{
bool isNum;
double retNum;
isNum = Double.TryParse(Convert.ToString(Expression), out retNum);
return isNum;
}
But the IsNumeric funciton returns "true" which is a lie.
I found the suggestion of the IsNumeric function here: How do I identify if a string is a number?
How can I check if an object is numeric or not?