Differences between referenceequals and equals in C #

Source: Internet
Author: User

Referenceequals () determines whether two strings point to the same memory address;

Equals: first, if two strings have the same memory location, the two strings are equal. Otherwise, the two strings are compared by character to determine whether they are equal.

The following is an example:

 

 String peom1 = "Kubla Khan"; <br/> string peom2 = "Kubla Khan"; <br/> string peom3 = string. copy (peom2); <br/> string peom4 = "Kubla Khan"; </P> <p> // referenceequals () determine whether two strings point to the same memory address <br/> console. writeline ("peom1 = peom2:" + (peom1 = peom2); // true <br/> console. writeline ("peom1 = peom3:" + (peom1 = peom3); // true <br/> console. writeline ("referenceequals (peom1, peom3):" + referenceequals (peom1, peom3); // false </P> <p> // equals, first, determine whether two strings have the same memory location, then the two strings are equal; otherwise, compare the two strings by character to determine whether they are equal <br/> console. writeline ("Equal (peom1, peom3):" + String. equals (peom1, peom2); // true <br/> console. writeline ("Equal (peom1, peom3):" + String. equals (peom1, peom3); // true

 

 

 

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.