Page 6 : 29
Object-oriented Programming in C#
Reference types, Value types, and Patterns
* Reference Types
Reference Types
Illustration of variables of reference types
Overview of reference types in C#
Comparing and copying objects via references
Equality in C#
* Value Types
Value types
Illustration of variables of value types
Structs in C#
Structs and Initialization
Structs versus classes
Examples of mutable structs in C#
Examples of immutable structs in C#
Boxing and Unboxing
Nullable types
* Organization of C# Programs
Program Organization
Examples of Program Organization
Namespaces and Visibility
Namespaces and Assemblies
* Patterns and Techniques
Design Patterns
Object-oriented Design Patterns
The Singleton pattern
A Singleton Random Class
Factory methods
Examples of Static Factory Methods
Privacy Leaks
Equality in C#
There are several different equality operations in C#. This page provides an overview.
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