Object called ToString(), which is handy for getting
a string representation of your object for output, even if only for debugging purposes. For
your custom classes, the default implementation of ToString() merely returns the type name
CHAPTER 9 n WORKING WITH STRINGS 169
of the object itself, and you??™ll need to implement your own override to do anything useful. All
of the built-in types do this, and if you call ToString() on a System.Integer, you??™ll get a string
representation of the value within. But what if you want the string representation in hexadecimal
format? For this case, you have another way to request the desired format, which involves
implementing the IFormattable interface, which looks like the following:
Public Interface IFormattable
Function ToString(ByVal Format As String, ByVal FormatProvider As _
IFormatProvider) As String
End Interface
All built-in numeric types, as well as date-time types, implement this interface. Using this
method, you can specify exactly how you want the value to be formatted by providing a format
specifier string. Before we get into exactly what the format strings look like, you should understand
a few more preliminary concepts, starting with the second parameter of the
IFormattable.ToString method.
Pages:
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287