Lecture overview -- Keyboard shortcut: 'u'  Previous page: Generic interfaces: IComparable<T> -- Keyboard shortcut: 'p'  Next page: Generic Classes and Inheritance -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 15 : 21
Object-oriented Programming in C#
Generic Types and Methods
Generic equality interfaces

The generic interface IEquatable<T> prescribes an Equals operation, and as such it is more fundamental than the interface IComparable<T>.

The generic interface IEqualityComparer<T> prescribes both Equals and GetHashCode.

/user/normark/oop-csharp-1/sources/c-sharp/interfaces/reproductions/IEquatable.csA reproduction of the generic interface IEquatable<T>.


/user/normark/oop-csharp-1/sources/c-sharp/interfaces/reproductions/IEqualityComparer.csA reproduction of the generic interface IEqualityComparer<T>.


  • Practical use of these interfaces

    • Collection classes of T elements often need to know if two elements of type T are equal to each other

    • From T it is possible to request a default equality comparer, which implements IEqualityComparer<T>