Prev | Current Page 579 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"

String() or vice versa?
??? Override Object.ToString(): The implementation inherited from Object.ToString()
merely returns a string name of the object??™s type.
??? Implement IFormattable if users need finer control over string formatting: Implement the Object.
ToString() override by calling IFormattable.ToString() with a format string of G and a
Nothing format provider.
??? Is an object convertible?
??? Override IConvertible so the class will work with System.Convert: In VB, you must implement
all methods of the interface. However, for conversion methods that don??™t make sense for your class,
simply throw an InvalidCastException object.
??? Should an object be immutable?
??? Consider making fields read-only and provide only read-only properties: Objects that fundamentally
represent a simple value, such as a string or a complex number, are excellent candidates to be
immutable objects.
??? Do you need to pass an object as a constant immutable method parameter?
??? Consider implementing an immutable shim class that contains a reference to a mutable object, which
can be passed a method parameter: First, see if it makes sense for your class to be immutable. If so,
then there??™s no need for this action. If you do need to be able to pass your mutable objects to methods
as immutable objects, you can achieve the same effect by using interfaces.


Pages:
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
wierszyki bajka Tango Olsztyn pozycjonowanie typy bukmacherskie