Skip to content

Instantly share code, notes, and snippets.

@craigtp
Last active Dec 20, 2015
Embed
What would you like to do?
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