System.IFormatProvider

This interface provides important functionality, allowing a class that implements the methods defined in this interface to customize formatted output. The IFormatProvider interface provides custom formatting for ToString. Some custom format codes already exist for numeric data types, date and time formatting, and enumerators. You can also provide your own formatting by inheriting from the IFormatProvider interface and implementing the methods specified.

You might want to look in the online documentation for “Custom Numeric Format Strings” because the documentation there is much more detailed than this appendix is able to cover. Listing B.8 shows an example of formatting a double (iformatprovider.cs).

Listing B.8. Numeric ...

Get .NET Common Language Runtime Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.