Prev | Current Page 559 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"

VB is one language that has taken a while to support
operator overloading, and it now only supports equality operators fully starting with
VB 2005. The best approach is to implement Object.Equals() as appropriate and base any
Operator = or Operator <> implementations on Equals() while only providing them as a
convenience for languages that support them.
nNote Consider implementing IEquatable(Of T) on your type to get a type-safe version of Equals(). This
is especially important for value types, since type-specific versions of methods avoid unnecessary boxing.
IfYou Override Equals(), Override GetHashCode()
GetHashCode() is called when objects are used as keys of a hash table. When a hash table
searches for an entry after given a key to look for, it asks the key for its hash code and then uses
that to identify which hash bucket the key lives in. Once it finds the bucket, it can then see if
that key is in the bucket. Theoretically, the search for the bucket should be quick, since the
buckets should have very few keys in them. This occurs if your GetHashCode method returns a
reasonably unique value for instances of your object that support value equivalence semantics.
From the previous discussion, you can see that it would be bad if your hash code algorithm
could return a different value between two instances that contain values that are equivalent.


Pages:
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
życzenia ślubne gustowne meble katowice felgi aluminiowe poznań katalog firm katalog stron