String - IsNumeric

A string extension method that query if the string object is numeric.

Try it

public static void Main()
{
	string [] values = {"EntityFramework", "13.5", "29", "SQL", "31"};

	foreach(var str in values)
	{
		// C# Extension Method: String - IsNumeric
    	if(str.IsNumeric())
		{
			Console.WriteLine(str);
		}
	}
}

View Source
using System.Text.RegularExpressions;

public static partial class Extensions
{
    /// <summary>
    ///     A string extension method that query if '@this' is numeric.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <returns>true if numeric, false if not.</returns>
    public static bool IsNumeric(this string @this)
    {
        return !Regex.IsMatch(@this, "[^0-9]");
    }
}