Prev | Current Page 581 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"

Similarly, value types have no need to implement the IDisposable interface, unless
they contain objects by reference, which implement IDisposable, or if they hold onto scarce
system resources. In those cases, it??™s important that value types implement IDisposable. You
can use the Using statement with value types that implement IDisposable.
CHAPTER 14 n VB 2008 BEST PRACTICES 362
nTip Since value types cannot implement finalizers, they cannot guarantee that the cleanup code in
Dispose() executes, even if the user forgets to call it explicitly. Therefore, declaring fields of reference
type within value types should be discouraged. If a field is a value type that requires disposal, you cannot
guarantee that disposal happens.
Value types and reference types do share many implementation idioms. For example, it
makes sense for both to consider implementing IComparable, IFormattable, and possibly
IConvertible.
In the rest of this section, we??™ll cover the different canonical concepts that you should apply
while designing value types. Specifically, you??™ll want to override Equals() for greater runtime efficiency,
and you??™ll want to be cognizant of what it means for a value type to implement an interface.
Override Equals() for Better Performance
You??™ve already seen the main differences between the two types of equivalence in the CLR and
in VB.


Pages:
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
przeszycia łódź poker zakłady bukmacherskie Wczasy nad morzem mimre.benton.pl