Differences between C # And F # over-load equal Operators

Source: Internet
Author: User

In C #, = and! = By default, the reference address is compared. If you want to change it to compare its connotation, You need to reload it. Generally, two operators and two functions need to be reloaded: The Equals function, the GetHashCode function, the operator =, and the operator! = There are two groups: The Equals function and the GetHashCode function. This group is used when the system compares objects. For example, if an object is placed in the Hashtable container, the system will compare and reject the same objects. The Equals and GetHashCode functions must be reloaded together. When you compare the meanings of two objects, do not reload = and! =, You can directly use the Overload Equals, but if the overload is used = and! =, It will be more intuitive. The two operators must be reloaded at the same time. If only one operator is reloaded, the compiler will prompt accordingly. Return to F #, corresponding to C #== and! = And <>. If you try to reload = or <>, the compiler will prompt you to reload Equals. When you call operators = and <>, Equals is automatically called. However, to Overload Equals, you must overload GetHashCode. So we can just reload this group of functions.

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.