//
Static members of System.Object.
Person p3 = new Person("Sally", "Jones", 4);
Person p4 = new Person("Sally", "Jones", 4);
Console.WriteLine("P3 and P4 have same state: {0}", object.Equals(p3, p4));
Console.WriteLine("P3 and P4 are pointing to same object: {0}",
object.ReferenceEquals(p3, p4));
}
Here, you are able to simply send in two objects (of any type) and allow the System.Object class
to determine the details automatically. These methods can be very helpful when you have redefined
equality for a custom type, yet still need to quickly determine whether two reference variables point
to the same location in memory (via the static ReferenceEquals() method).
Do'stlaringiz bilan baham: |