Last active
December 20, 2015 02:59
-
-
Save craigtp/6060807 to your computer and use it in GitHub Desktop.
A C# IsNumeric function, written as an extension method.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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