3.12. Formatting

As we already know from our discussion of the Object class, every class in the .NET Framework class library has the ToString() method. Implementations of this method vary from class to class, but for the value types, especially for the primitive ones, we can use this method to output their values. In the following sections we will see how to use various formatting specifiers to format the values as currency, decimal, exponential, hexadecimal, and so on.

Default formatting

By default, when we use the Console.WriteLine(), or any other method that implicitly converts the value to a String, it is the ToString() method that performs the action. For example, the following code:

 '--------------------------------------- ' .NET Formatting ...

Get A Programmer's Guide to .NET now with O’Reilly online learning.

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