Suppose I have a class Tthat I want to use as a key in a collection Dictionary<T,U>.
T
Dictionary<T,U>
What should I implement in Tso that these keys are based on values T, not references T?
I hope this is easy GetHashCode().
GetHashCode()
You must implement GetHashCode () and Equals ().
The dictionary is a Hashtable under the covers, so you can read this: Peer Traps / GetHashCode - How does the hash table work?
IEqualityComparer<T> , EqualityComparer<T>.Default, MSDN :
IEqualityComparer<T>
EqualityComparer<T>.Default
Default , T System.IEquatable(Of T) , , EqualityComparer (Of T), . , EqualityComparer (Of T), Object.Equals Object.GetHashCode, T.
, IEquatable<T> ( , Equals GetHashCode) .
IEquatable<T>
Equals
GetHashCode
Equals GetHashCode, IEqualityComparer<T>, .
IEqualityComparer<T>: - - . , . , , IEquatable<T> ... . ( IEqualityComparer<T> , , .)
Equals(object obj). , GetHashCode Equals. MSDN.
Equals(object obj)
Source: https://habr.com/ru/post/1746550/More articles:Doubt in Vptr - you need to know how it gets the Vtable address - c ++Unable to get correct text height in java.awt.BufferdImage / Graphics2D - javaAesManaged и RijndaelManaged - cryptographyJQuery Error "Access Denied" - javascriptС++ - полностью приостановить работу с окнами - c++How to determine an element by index in a template - algorithmWhen will we use pushScene and replaceScene? - cocoa-touchbundles in java? - javaCan i use notepad ++ exe in my application? - c #Protection protection of my applications from disassembler - androidAll Articles