O'Reilly logo

A Programmer's Guide to .NET by Alexei Fedorov

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

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 ...

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