Scenario 1
String s = "Test ";
String t = string. Copy (s );
Console. WriteLine (s = t );
Console. WriteLine (object) s = (object) t );
The output is true and false.
Case 2
String s = "Test ";
String t = s;
Console. WriteLine (s = t );
Console. WriteLine (object) s = (object) t );
True for output
Case 3
String s = "Test ";
String t = string. Copy (s );
Console. WriteLine (s. Equals (t); // true
Console. WriteLine (object) s. Equals (object) t); // true
Case 4
String s = "Test ";
String t = s;
Console. WriteLine (s. Equals (t); // true
Console. WriteLine (object) s. Equals (object) t); // true
Conclusion:
String. Equals (); Method (inherited from its superclass Object by the String class) is used to detect whether two objects are equal, that is, whether the content of the two objects is equal.
= It has different functions for comparing and referencing basic data types:
Compares the basic data types. If the two values are the same, the result is true.
When comparing references, if the reference points to the same object in the memory (that is, the memory address is the same), the result is true.