Prev | Current Page 593 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"

Object, provide an overload that
uses the concrete value type in its place. That way, clients of the value type can avoid unnecessary
boxing. For interfaces, consider hiding the type-less implementation behind explicit interface
implementation, if desired.
??? Do you need to modify boxed instances of value?
??? Implement an interface to do so: Calling through an interface member implemented by a value
type is the only way to change a value type within a boxed instance.
??? Are values of this type comparable?
??? Implement IComparable and override Equals() and GetHashCode(): You??™ll want to override
these as a triplet, since they have intertwined implementations. If you override Equals(), take
the previous advice and create a type-safe version as well.
continued
CHAPTER 14 n VB 2008 BEST PRACTICES 371
CHECKLIST FOR VALUE TYPES
??? Is the value convertible to System.String() or vice versa?
??? Override ValueType.ToString(): The implementation inherited from ValueType merely
returns a string name of the value??™s type.
??? Implement IFormattable if users need finer control over string formatting: Implement a
ValueType.ToString() override that calls IFormattable.ToString() with a format
string of G and a Nothing format provider.
??? Is the value convertible?
??? Override IConvertible so structures will work with System.


Pages:
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
fenomenalne mieszkania do wynajęcia warszawa życzenia ślubne studia podyplomowe Łódź Tango Olsztyn texas holdem