Checking for Valid Numeric Value

Unfortunately to do so, it must rely on an exception to detect a invalid value which is a little bit of a performance hit.

public static bool IsNumeric(object value) 
{ 
  bool returnValue = false;
  try
    {
      double check = double.Parse(value.ToString(), NumberStyles.Any, 
NumberFormatInfo.CurrentInfo);
      returnValue = true;
    }
  catch
    {}
  return returnValue;
}

I would think that this would also work in normal C# applications.

Tip Submitted By: David McCarter


Discover more from dotNetTips.com

Subscribe to get the latest posts sent to your email.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.