By default (that is, if the type does not overload the = = operator), the = = operator Determines whether two values in the stack are equal. To verify this conclusion, consider the following procedure:
Namespace Judgeequals
{
Class Program
{
static void Main (string[] args)
{
int a = 10;
int B = 10;
Console.WriteLine (A==B);
string S1 = "abc";
string s2 = "abc";
Console.WriteLine (S1==S2);
person P1 = new person ();
person P2 = new person ();
Console.WriteLine (P1==P2);
Console.readkey ();
}
}
public class Person
{
public string Name {get; set;}
public int Age {get; set;}
public string Email {get; set;}
}
}
The results of the above program operation are as follows:
Console.readkey () in the main method, add a breakpoint to the line, and then press to debug. Then enter &A,&B,&S1,&S2,&P1,&P2 in the Immediate window to get the following information:
It can be concluded that the = = operator is to determine whether two values in the stack are equal. But you may have another question, which is why S1 and S2 have the same two storage addresses? The simple point is that the CLR maintains a string constant resident pool, and the CLR will go to the resident pool to query whether the string constant exists before creating a new string constant. Returns the corresponding address if it exists, or creates a new string constant and returns it.
The = = operator Determines whether two values in the stack are equal