O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parsing Text to Objects

Converting objects to a textual representation is one thing, dealing with user (or text file and so on) input and turning it into rich objects is another thing. You’ve already seen a whole set of Parse, TryParse, and Exact variants, but you want to note a few more things.

Sometimes going back and forth between objects and text is not a lossless conversion. In such cases, the framework often provides a format string named R to emit a text representation that will restore the original value when using a Parse method. A good example is floating-point numbers, whose decimal representation is not exact:

double value = 1.0 / 3.0;string text = value.ToString();Console.WriteLine(text);               // ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required