Relationship between gethashcode equals and dictionary, hash, and list

Source: Internet
Author: User

Dictionary, hashset, and list can all see functions such as contains.

For example, dictionary. the containskey (keytest) function first calls keytest. gethashcode compares whether such a hashcode already exists. If yes, true is returned directly. If no, it cannot be determined that such a key does not exist, because hashcode may conflict with each other. (If hash is equivalent, the objects must be equal. If they are not equal, the objects may be unequal ), therefore, use the override method equals to search for the data.

The default equals is referenceequals for objects.

That is to say, if you are lazy, you can not write gethashcode, as long as you write equals, those structures such as dictionary are normal, but the performance is poor. After all, hashcode is faster and faster.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.