IsNumeric() in c#.net?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello, friends,

In VB6, we have function IsNumeric(). What is the correpsonding function in
c#.net?

Thanks.
 
Hello, friends,

In VB6, we have function IsNumeric(). What is the correpsonding function in
c#.net?

Thanks.

This is what I've found when searching through www.google.com/codesearch,
i've put it in a class for easy access throughout the application:


/// <summary>
/// Returns whether an object is numeric or not
/// </summary>
/// <param name="o">object to check</param>
/// <returns>boolean true/false</returns>
public static bool IsNumeric(object o)
{
if (o is IConvertible)
{
TypeCode tc = ((IConvertible)o).GetTypeCode();
if (TypeCode.Char <= tc && tc <= TypeCode.Decimal)
return true;
}
return false;
}
 
This is what I've found when searching throughwww.google.com/codesearch,
i've put it in a class for easy access throughout the application:

That's not what's being asked for in this case, I believe. For
instance, it returns false for "5". It's not a case of asking whether
the type is a numeric type, so much as whether a particular object can
be converted into a number without error.

Jon
 
Back
Top