I know a few ways how to check this. regex,int.parse,tryparse,looping.
int.parse
tryparse
can anyone tell me what is the fastest way to check?
the nee
Try this code:
bool isDigitsOnly(string str) { try { int number = Convert.ToInt32(str); return true; } catch (Exception) { return false; } }
Another approach!
string str = "12345"; bool containsOnlyDigits = true; try { Convert.ToInt32(str); } catch { containsOnlyDigits = false; }