To determine whether a string is a valid representation of a specified numeric type, use the staticTryParse method that is implemented by all primitive numeric types and also by types such asDateTime andIPAddress. The following example shows how to determine whether "108" is a validint.
Primitive numeric types also implement the Parse static method, which throws an exception if the string is not a valid number.TryParse is generally more efficient because it just returns false if the number is not valid.
Always use the TryParse or Parse methods to validate user input from controls such as text boxes and combo boxes.