How to check whether string is a Number or not in C#

Rajesh_Kumar
Posted by Rajesh_Kumar under C# category on | Points: 40 | Views : 673
public static Bool IsNumeric(Object Expression)
{
if(Expression == null || Expression is DateTime)
return false;

if(Expression is Int16 || Expression is Int32 || Expression is Int64 || Expression is Decimal || Expression is Single || Expression is Double || Expression is Boolean)
return true;

try
{
if(Expression is string)
Double.Parse(Expression as string);
else
Double.Parse(Expression.ToString());
return true;
} catch {}
return false;
}
}

Comments or Responses

Login to post response