-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathIEqualityComparer`1.xml
235 lines (221 loc) · 17.4 KB
/
IEqualityComparer`1.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<Type Name="IEqualityComparer<T>" FullName="System.Collections.Generic.IEqualityComparer<T>">
<TypeSignature Language="C#" Value="public interface IEqualityComparer<in T>" FrameworkAlternate="dotnet-uwp-10.0;net-10.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.6.2-pp;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-1.0;netstandard-1.1;netstandard-1.2;netstandard-1.3;netstandard-1.4;netstandard-1.5;netstandard-1.6;netstandard-2.0;netstandard-2.1" />
<TypeSignature Language="ILAsm" Value=".class public interface auto ansi abstract IEqualityComparer`1<- T>" FrameworkAlternate="dotnet-uwp-10.0;net-5.0;net-6.0;net-7.0;netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.6.2-pp;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-1.0;netstandard-1.1;netstandard-1.2;netstandard-1.3;netstandard-1.4;netstandard-1.5;netstandard-1.6;netstandard-2.0;netstandard-2.1" />
<TypeSignature Language="DocId" Value="T:System.Collections.Generic.IEqualityComparer`1" />
<TypeSignature Language="VB.NET" Value="Public Interface IEqualityComparer(Of In T)" FrameworkAlternate="dotnet-uwp-10.0;net-10.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.6.2-pp;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-1.0;netstandard-1.1;netstandard-1.2;netstandard-1.3;netstandard-1.4;netstandard-1.5;netstandard-1.6;netstandard-2.0;netstandard-2.1" />
<TypeSignature Language="F#" Value="type IEqualityComparer<'T> = interface" />
<TypeSignature Language="C++ CLI" Value="generic <typename T>
public interface class IEqualityComparer" />
<TypeSignature Language="ILAsm" Value=".class public interface auto ansi abstract beforefieldinit IEqualityComparer`1<- T>" FrameworkAlternate="net-10.0;net-8.0;net-9.0" />
<TypeSignature Language="C#" Value="public interface IEqualityComparer<T>" FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5" />
<TypeSignature Language="ILAsm" Value=".class public interface auto ansi abstract IEqualityComparer`1<T>" FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5" />
<TypeSignature Language="VB.NET" Value="Public Interface IEqualityComparer(Of T)" FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5" />
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<TypeForwardingChain>
<TypeForwarding From="mscorlib" FromVersion="4.0.0.0" To="System.Runtime" ToVersion="0.0.0.0" FrameworkAlternate="dotnet-uwp-10.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="10.0.0.0" FrameworkAlternate="net-10.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="5.0.0.0" FrameworkAlternate="net-5.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="6.0.0.0" FrameworkAlternate="net-6.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="7.0.0.0" FrameworkAlternate="net-7.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="8.0.0.0" FrameworkAlternate="net-8.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="9.0.0.0" FrameworkAlternate="net-9.0" />
<TypeForwarding From="System.Runtime" FromVersion="4.1.1.1" To="mscorlib" ToVersion="4.0.0.0" FrameworkAlternate="netframework-4.6.2-pp" />
</TypeForwardingChain>
<TypeParameters>
<TypeParameter Name="T">
<Constraints>
<ParameterAttribute>Contravariant</ParameterAttribute>
</Constraints>
</TypeParameter>
</TypeParameters>
<Interfaces />
<Docs>
<typeparam name="T">The type of objects to compare.</typeparam>
<summary>Defines methods to support the comparison of objects for equality.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This interface allows the implementation of customized equality comparison for collections. That is, you can create your own definition of equality for type `T`, and specify that this definition be used with a collection type that accepts the <xref:System.Collections.Generic.IEqualityComparer%601> generic interface. In the .NET Framework, constructors of the <xref:System.Collections.Generic.Dictionary%602> generic collection type accept this interface.
A default implementation of this interface is provided by the <xref:System.Collections.Generic.EqualityComparer%601.Default%2A> property of the <xref:System.Collections.Generic.EqualityComparer%601> generic class. The <xref:System.StringComparer> class implements <xref:System.Collections.Generic.IEqualityComparer%601> of type <xref:System.String>.
This interface supports only equality comparisons. Customization of comparisons for sorting and ordering is provided by the <xref:System.Collections.Generic.IComparer%601> generic interface.
We recommend that you derive from the <xref:System.Collections.Generic.EqualityComparer%601> class instead of implementing the <xref:System.Collections.Generic.IEqualityComparer%601> interface, because the <xref:System.Collections.Generic.EqualityComparer%601> class tests for equality using the <xref:System.IEquatable%601.Equals%2A?displayProperty=nameWithType> method instead of the <xref:System.Object.Equals%2A?displayProperty=nameWithType> method. This is consistent with the `Contains`, `IndexOf`, `LastIndexOf`, and `Remove` methods of the <xref:System.Collections.Generic.Dictionary%602> class and other generic collections.
## Examples
The following example adds custom `Box` objects to a dictionary collection. The `Box` objects are considered equal if their dimensions are the same.
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/IEqualityComparerT/Overview/program.cs" interactive="try-dotnet" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.collections.generic.iequalitycomparer/vb/program.vb" id="Snippet1":::
]]></format>
</remarks>
<altmember cref="T:System.Collections.Generic.EqualityComparer`1" />
<altmember cref="T:System.Collections.Generic.Dictionary`2" />
<altmember cref="Overload:System.Collections.Generic.Dictionary`2.#ctor" />
<altmember cref="T:System.Collections.Generic.IComparer`1" />
</Docs>
<Members>
<Member MemberName="Equals">
<MemberSignature Language="C#" Value="public bool Equals (T x, T y);" FrameworkAlternate="dotnet-uwp-10.0;netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.6.2-pp;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-1.0;netstandard-1.1;netstandard-1.2;netstandard-1.3;netstandard-1.4;netstandard-1.5;netstandard-1.6;netstandard-2.0;netstandard-2.1" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance bool Equals(!T x, !T y) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Collections.Generic.IEqualityComparer`1.Equals(`0,`0)" />
<MemberSignature Language="VB.NET" Value="Public Function Equals (x As T, y As T) As Boolean" />
<MemberSignature Language="F#" Value="abstract member Equals : 'T * 'T -> bool" Usage="iEqualityComparer.Equals (x, y)" />
<MemberSignature Language="C#" Value="public bool Equals (T? x, T? y);" FrameworkAlternate="net-10.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0" />
<MemberSignature Language="C++ CLI" Value="public:
 bool Equals(T x, T y);" FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="x" Type="T">
<Attributes>
<Attribute FrameworkAlternate="netcore-3.0;netcore-3.1;netframework-4.6.2-pp">
<AttributeName Language="C#">[System.Diagnostics.CodeAnalysis.AllowNull]</AttributeName>
<AttributeName Language="F#">[<System.Diagnostics.CodeAnalysis.AllowNull>]</AttributeName>
</Attribute>
</Attributes>
</Parameter>
<Parameter Name="y" Type="T">
<Attributes>
<Attribute FrameworkAlternate="netcore-3.0;netcore-3.1;netframework-4.6.2-pp">
<AttributeName Language="C#">[System.Diagnostics.CodeAnalysis.AllowNull]</AttributeName>
<AttributeName Language="F#">[<System.Diagnostics.CodeAnalysis.AllowNull>]</AttributeName>
</Attribute>
</Attributes>
</Parameter>
</Parameters>
<Docs>
<param name="x">The first object of type <paramref name="T" /> to compare.</param>
<param name="y">The second object of type <paramref name="T" /> to compare.</param>
<summary>Determines whether the specified objects are equal.</summary>
<returns>
<see langword="true" /> if the specified objects are equal; otherwise, <see langword="false" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Implement this method to provide a customized equality comparison for type `T`.
]]></format>
</remarks>
<block subset="none" type="overrides">
<para>Implementations are required to ensure that if the <see cref="M:System.Collections.Generic.IEqualityComparer`1.Equals(`0,`0)" /> method returns <see langword="true" /> for two objects <paramref name="x" /> and <paramref name="y" />, then the value returned by the <see cref="M:System.Collections.Generic.IEqualityComparer`1.GetHashCode(`0)" /> method for <paramref name="x" /> must equal the value returned for <paramref name="y" />.
The <see cref="M:System.Collections.Generic.IEqualityComparer`1.Equals(`0,`0)" /> method is reflexive, symmetric, and transitive. That is, it returns <see langword="true" /> if used to compare an object with itself; <see langword="true" /> for two objects <paramref name="x" /> and <paramref name="y" /> if it is <see langword="true" /> for <paramref name="y" /> and <paramref name="x" />; and <see langword="true" /> for two objects <paramref name="x" /> and <paramref name="z" /> if it is <see langword="true" /> for <paramref name="x" /> and <paramref name="y" /> and also <see langword="true" /> for <paramref name="y" /> and <paramref name="z" />.</para>
</block>
</Docs>
</Member>
<Member MemberName="GetHashCode">
<MemberSignature Language="C#" Value="public int GetHashCode (T obj);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance int32 GetHashCode(!T obj) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Collections.Generic.IEqualityComparer`1.GetHashCode(`0)" />
<MemberSignature Language="VB.NET" Value="Public Function GetHashCode (obj As T) As Integer" />
<MemberSignature Language="F#" Value="abstract member GetHashCode : 'T -> int" Usage="iEqualityComparer.GetHashCode obj" />
<MemberSignature Language="C++ CLI" Value="public:
 int GetHashCode(T obj);" FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
<AssemblyVersion>10.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="obj" Type="T">
<Attributes>
<Attribute FrameworkAlternate="net-10.0;net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-3.0;netcore-3.1;netframework-4.6.2-pp">
<AttributeName Language="C#">[System.Diagnostics.CodeAnalysis.DisallowNull]</AttributeName>
<AttributeName Language="F#">[<System.Diagnostics.CodeAnalysis.DisallowNull>]</AttributeName>
</Attribute>
</Attributes>
</Parameter>
</Parameters>
<Docs>
<param name="obj">The <see cref="T:System.Object" /> for which a hash code is to be returned.</param>
<summary>Returns a hash code for the specified object.</summary>
<returns>A hash code for the specified object.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Implement this method to provide a customized hash code for type `T`, corresponding to the customized equality comparison provided by the <xref:System.Collections.Generic.IEqualityComparer%601.Equals%2A> method.
]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">The type of <paramref name="obj" /> is a reference type and <paramref name="obj" /> is <see langword="null" />.</exception>
<block subset="none" type="overrides">
<para>Implementations are required to ensure that if the <see cref="M:System.Collections.Generic.IEqualityComparer`1.Equals(`0,`0)" /> method returns <see langword="true" /> for two objects <paramref name="x" /> and <paramref name="y" />, then the value returned by the <see cref="M:System.Collections.Generic.IEqualityComparer`1.GetHashCode(`0)" /> method for <paramref name="x" /> must equal the value returned for <paramref name="y" />.</para>
</block>
<altmember cref="M:System.Object.GetHashCode" />
<altmember cref="T:System.Collections.IHashCodeProvider" />
</Docs>
</Member>
</Members>
</Type>