I am just curious to know why the C# language team has not provided a IsNumeric function on the String object?. IsNumeric function would have been more proper on a String object that the Int32.TryParse Function.
Note: I am asking this question because I have found it difficult to explain this to a beginner and I don’t like them cursing C# for this!
Update: Please, this question is not about how to Implement a IsNumeric function.
The trouble with a method like that would be deciding what counts as “numeric”. Should it allow decimals points, should it allow leading whitespace, should it have an upper bound for the number of digits?
Int32.TryParse answers the much more well-defined question of, “is this a valid string representation of an Int32?”
And of course, nothing is stopping you writing your own extension method, that decides if a string is numeric according to your own rules.