In the preceding section, I explained how to take an object and obtain a string representation of that object. In this section, I’ll talk about the opposite: how to take a string and obtain an object representation of it. Obtaining an object from a string isn’t a very common operation, but it does occasionally come in handy. Microsoft felt it necessary to formalize a mechanism by which strings can be parsed into objects.
Any type that can parse a string offers a public, static method called
Parse. This method takes a
String and returns an instance of the type; in a way,
Parse acts like a constructor. In the FCL, a
Parse method exists on all the numeric types as well as for
TimeSpan, and a few other ...