In general, most of the developers are not aware of the inbuilt methods available for validating the primitive data types like
and end up doing a custom implementation. The function below is a sample of that custom implementation to validate whether the given
is numeric or not.
public bool CheckIfNumeric(string value)
bool isNumeric = true;
int i = Convert.ToInt32(value);
isNumeric = false;
Since it involves
, it is not the best way. A better approach would be to use
as shown below:
int output = 0;
bool isNumeric = int.TryParse(value, out output);
, in my opinion, is definitely the faster and cleaner way.
Keep a watch for more...