Reference types, Value types, and Patterns
- slide 6 : 29
Equality in C#
There are several equality operations in C# on reference types
Equals in class Object
ReferenceEquals in class Object
Overriding Equals in C#
o1.Equals(o2)
-
equality
By default, true if
o1
and
o2
are created by execution of the same
new
Can be redefined in a particular class
Object.ReferenceEquals(o1, o2)
-
identity
True if both
o1
and
o2
are
null
, or if they are created by execution of the same
new
Static - cannot be redefined.
Object.Equals(o1, o2)
True if
Object.ReferenceEquals(o1, o2)
, or if
o1.Equals(o2)
o1 == o2
True if both
o1
and
o2
are null, or if they are created by execution of the same
new
An overloadable operator
Equality of value types and reference types