Skip to content

Instantly share code, notes, and snippets.

@craigtp
Last active December 20, 2015 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigtp/6060807 to your computer and use it in GitHub Desktop.
Save craigtp/6060807 to your computer and use it in GitHub Desktop.
A C# IsNumeric function, written as an extension method.
using System;
using System.Globalization;
namespace NumberFunctionUtilities
{
public static class NumberFunctions
{
public static bool IsNumeric(this object expression)
{
if (expression == null)
{
return false;
}
double number;
return Double.TryParse(Convert.ToString(expression, CultureInfo.InvariantCulture), NumberStyles.Any, NumberFormatInfo.InvariantInfo, out number);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment