IFormatProvider
looks like this:
Public Interface IFormatProvider
Function GetFormat(ByVal formatType As Type) As Object
End Interface
In an effort to be as generic as possible, GetFormat() is designed to accept an object of type
System.Type. Thus it is extensible as to what types the object that implements IFormatProvider
may support. This flexibility is handy if you intend to develop custom format providers that
need to return as-of-yet-undefined formatting information.
The standard library provides a System.Globalization.CultureInfo type that will most
likely suffice for all of your needs. The CultureInfo object implements the IFormatProvider
interface, and you can pass instances of it as the second parameter to IFormattable.
ToString(). Soon, you??™ll see an example of its usage when you make modifications to the
ComplexNumber example, but first, let??™s look at the first parameter to ToString().
The format parameter of ToString() allows you to specify how to format a specific number.
The format provider can describe how to display a date or how to display currency based upon
cultural preferences, but you still need to know how to format the object in the first place. In a
nutshell, the format string consists of a single letter specifying the format, and then an optional
number between 0 and 99 that declares the precision.
Pages:
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531