C# Equivalent to IsNumeric





























C# Equivalent to IsNumeric

C# has no built-in equivalent to VB's IsNumeric function.  In fact, there is no single method call in all of the .NET Framework that simulates IsNumeric.  The best alternative in C# is to write your own method similar to the following:

 

internal static bool IsNumeric(object ObjectToTest)
{
    if (ObjectToTest == null)

    {
        return false;

    }
    else
    {
        double OutValue;
        return double.TryParse(ObjectToTest.ToString().Trim(),
            System.Globalization.NumberStyles.Any,

            System.Globalization.CultureInfo.CurrentCulture,

            out OutValue);
    }
}
 

If you need to convert from VB to C# and you are depending on the results being reliable and accurate, then you will want to have Instant C#, the best VB to C# converter, at your fingertips.

 

 
 
Email your questions and comments to:  info@tangiblesoftwaresolutions.com

[Site Map]        [Home]


Copyright © 1997 - 2009 Tangible Software Solutions Inc.