Search This Blog

Wednesday, October 15, 2008

C# Equivalent of VB's IsNumeric()

C# calls Equivalent of VB's IsNumeric() from CodeProject

Int32.TryParse() Method

int result;
if (int.TryParse("123", out result))
{
Debug.WriteLine("Valid integer: " + result);
}
else
{
Debug.WriteLine("Not a valid integer");
}

// throws ArgumentNullExceptionint
result1 = Int32.Parse(null);

// doesn't throw an exception, returns 0
int result2 = Convert.ToInt32(null);

No comments: