Funny how sometimes the simplest functions are the hardest to find. The other day I needed to test a value to see if it wa numeric. I stupidly assumed that I could write something like

string s = “123”;
if (isNumeric(s))
{
//do stuff
}

And quickly realized this wasn’t going to work when VisualStudio threw a compile time error. After (too) much digging I discovered that the function exists and it is actually a method of the char type. Therefore

string s = "123";
if(char.IsNumber(s))
{
//do stuff
}

Advertisements