If I have these strings:
\"abc\"
= false
\"123\"
= true
\"ab2\"
If you want to check if a string is a number (I'm assuming it's a string since if it's a number, duh, you know it's one).
you could also do:
public static bool IsNumber(this string aNumber)
{
BigInteger temp_big_int;
var is_number = BigInteger.TryParse(aNumber, out temp_big_int);
return is_number;
}
This will take care of the usual nasties:
BigInteger.Parse("3.3")
will throw an exception, and TryParse
for the same will return false)Double.TryParse
You'll have to add a reference to System.Numerics
and have
using System.Numerics;
on top of your class (well, the second is a bonus I guess :)