About This eBook 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

O'Reilly logo

Formatting Text

One common operation is to represent objects in a textual form. By now, the first thought that should come to mind is to use ToString. In the light of localization and the fact that many types of objects can have different textual representations, the simple method provided by System.Object does not always suffice, though:

public virtual string ToString();

In particular, the lack of one or more parameters to control the desired result makes this overload not always applicable. MSDN defines the ToString method as follows:

This method returns a human-readable string that is culture-sensitive.

The IFormattable Interface

Also, the documentation states that other ToString methods can be provided through an interface called IFormattable ...

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