Quite often, string objects are used to accept inputs that have a certain structured form, like a number’s string representation or a URI. In such a case, the String type does not support enough validation of input by itself, and additional checking will be carried out by the consumer of the string object. For example, a number consists of digits, possibly with a decimal separator character, a sign character, or an exponent used in scientific notation. If this form is not respected for the string-based input, a FormatException is raised.

The static Parse methods on numeric types provide an example:

int invalid= int.Parse("Hello");

Notice that those methods provide additional parameters to regulate accepted input formats (for example, ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.