|
76 | 76 | <typeparam name="T">The type of objects to compare.</typeparam> |
77 | 77 | <summary>Provides a base class for implementations of the <see cref="T:System.Collections.Generic.IEqualityComparer`1" /> generic interface.</summary> |
78 | 78 | <remarks> |
79 | | - <format type="text/markdown"><![CDATA[ |
80 | | - |
81 | | -## Remarks |
82 | | -
|
83 | | -Derive from this class to provide a custom implementation of the <xref:System.Collections.Generic.IEqualityComparer%601> generic interface for use with collection classes such as the <xref:System.Collections.Generic.Dictionary%602> generic class, or with methods such as <xref:System.Collections.Generic.List%601.Sort%2A?displayProperty=nameWithType>. |
84 | | -
|
85 | | -The <xref:System.Collections.Generic.EqualityComparer%601.Default%2A> property checks whether type `T` implements the <xref:System.IEquatable%601?displayProperty=nameWithType> generic interface and, if so, returns an <xref:System.Collections.Generic.EqualityComparer%601> that invokes the implementation of the <xref:System.IEquatable%601.Equals%2A?displayProperty=nameWithType> method. Otherwise, it returns an <xref:System.Collections.Generic.EqualityComparer%601>, as provided by `T`. |
86 | | -
|
87 | | -In .NET 8 and later versions, we recommend using the <xref:System.Collections.Generic.EqualityComparer%601.Create(System.Func{%600,%600,System.Boolean},System.Func{%600,System.Int32})?displayProperty=nameWithType> method to create instances of this type. |
88 | | -
|
89 | | -## Examples |
90 | | - The following example creates a dictionary collection of objects of type `Box` with an equality comparer. Two boxes are considered equal if their dimensions are the same. It then adds the boxes to the collection. |
91 | | - |
92 | | - The dictionary is recreated with an equality comparer that defines equality in a different way: Two boxes are considered equal if their volumes are the same. |
93 | | - |
94 | | - :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/EqualityComparerT/Overview/program.cs" interactive="try-dotnet" id="Snippet1"::: |
95 | | - :::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/EqualityComparerT/Overview/program.vb" id="Snippet1"::: |
96 | | -
|
| 79 | + <format type="text/markdown"><![CDATA[ |
| 80 | + |
| 81 | +## Remarks |
| 82 | +
|
| 83 | +Derive from this class to provide a custom implementation of the <xref:System.Collections.Generic.IEqualityComparer%601> generic interface for use with collection classes such as the <xref:System.Collections.Generic.Dictionary%602> generic class, or with methods such as <xref:System.Collections.Generic.List%601.Sort%2A?displayProperty=nameWithType>. |
| 84 | +
|
| 85 | +The <xref:System.Collections.Generic.EqualityComparer%601.Default%2A> property checks whether type `T` implements the <xref:System.IEquatable%601?displayProperty=nameWithType> generic interface and, if so, returns an <xref:System.Collections.Generic.EqualityComparer%601> that invokes the implementation of the <xref:System.IEquatable%601.Equals%2A?displayProperty=nameWithType> method. Otherwise, it returns an <xref:System.Collections.Generic.EqualityComparer%601>, as provided by `T`. |
| 86 | +
|
| 87 | +In .NET 8 and later versions, we recommend using the <xref:System.Collections.Generic.EqualityComparer%601.Create(System.Func{%600,%600,System.Boolean},System.Func{%600,System.Int32})?displayProperty=nameWithType> method to create instances of this type. |
| 88 | +
|
| 89 | +## Examples |
| 90 | + The following example creates a dictionary collection of objects of type `Box` with an equality comparer. Two boxes are considered equal if their dimensions are the same. It then adds the boxes to the collection. |
| 91 | + |
| 92 | + The dictionary is recreated with an equality comparer that defines equality in a different way: Two boxes are considered equal if their volumes are the same. |
| 93 | + |
| 94 | + :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/EqualityComparerT/Overview/program.cs" id="Snippet1"::: |
| 95 | + :::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/EqualityComparerT/Overview/program.vb" id="Snippet1"::: |
| 96 | +
|
97 | 97 | ]]></format> |
98 | 98 | </remarks> |
99 | 99 | <altmember cref="T:System.Collections.Generic.IEqualityComparer`1" /> |
@@ -180,7 +180,7 @@ In .NET 8 and later versions, we recommend using the <xref:System.Collections.Ge |
180 | 180 | </Parameters> |
181 | 181 | <Docs> |
182 | 182 | <param name="equals">The delegate to use to implement the <see cref="M:System.Collections.Generic.EqualityComparer`1.Equals(`0,`0)" /> method.</param> |
183 | | - <param name="getHashCode">The delegate to use to implement the <see cref="M:System.Collections.Generic.EqualityComparer`1.GetHashCode(`0)" /> method. |
| 183 | + <param name="getHashCode">The delegate to use to implement the <see cref="M:System.Collections.Generic.EqualityComparer`1.GetHashCode(`0)" /> method. |
184 | 184 | If no delegate is supplied, calls to the resulting comparer's <see cref="M:System.Collections.Generic.EqualityComparer`1.GetHashCode(`0)" /> will throw <see cref="T:System.NotSupportedException" />.</param> |
185 | 185 | <summary>Creates an <see cref="T:System.Collections.Generic.EqualityComparer`1" /> by using the specified delegates as the implementation of the comparer's <see cref="M:System.Collections.Generic.EqualityComparer`1.Equals(`0,`0)" /> and <see cref="M:System.Collections.Generic.EqualityComparer`1.GetHashCode(`0)" /> methods.</summary> |
186 | 186 | <returns>The new comparer.</returns> |
@@ -238,23 +238,23 @@ In .NET 8 and later versions, we recommend using the <xref:System.Collections.Ge |
238 | 238 | <summary>Returns a default equality comparer for the type specified by the generic argument.</summary> |
239 | 239 | <value>The default instance of the <see cref="T:System.Collections.Generic.EqualityComparer`1" /> class for type <typeparamref name="T" />.</value> |
240 | 240 | <remarks> |
241 | | - <format type="text/markdown"><![CDATA[ |
242 | | - |
243 | | -## Remarks |
244 | | - The <xref:System.Collections.Generic.EqualityComparer%601.Default%2A> property checks whether type `T` implements the <xref:System.IEquatable%601?displayProperty=nameWithType> interface and, if so, returns an <xref:System.Collections.Generic.EqualityComparer%601> that uses that implementation. Otherwise, it returns an <xref:System.Collections.Generic.EqualityComparer%601> that uses the overrides of <xref:System.Object.Equals%2A?displayProperty=nameWithType> and <xref:System.Object.GetHashCode%2A?displayProperty=nameWithType> provided by `T`. |
245 | | - |
246 | | - |
247 | | - |
248 | | -## Examples |
249 | | - The following example creates a collection that contains elements of the `Box` type and then searches it for a box matching another box by calling the `FindFirst` method, twice. |
250 | | - |
251 | | - The first search does not specify any equality comparer, which means `FindFirst` uses <xref:System.Collections.Generic.EqualityComparer%601.Default%2A?displayProperty=nameWithType> to determine equality of boxes. That in turn uses the implementation of the <xref:System.IEquatable%601.Equals%2A?displayProperty=nameWithType> method in the `Box` class. Two boxes are considered equal if their dimensions are the same. |
252 | | - |
253 | | - The second search specifies an equality comparer (`BoxEqVolume`) that defines equality by volume. Two boxes are considered equal if their volumes are the same. |
254 | | - |
255 | | - :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/EqualityComparerT/Default/program.cs" interactive="try-dotnet"::: |
256 | | - :::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/EqualityComparerT/Default/program.vb"::: |
257 | | -
|
| 241 | + <format type="text/markdown"><![CDATA[ |
| 242 | + |
| 243 | +## Remarks |
| 244 | + The <xref:System.Collections.Generic.EqualityComparer%601.Default%2A> property checks whether type `T` implements the <xref:System.IEquatable%601?displayProperty=nameWithType> interface and, if so, returns an <xref:System.Collections.Generic.EqualityComparer%601> that uses that implementation. Otherwise, it returns an <xref:System.Collections.Generic.EqualityComparer%601> that uses the overrides of <xref:System.Object.Equals%2A?displayProperty=nameWithType> and <xref:System.Object.GetHashCode%2A?displayProperty=nameWithType> provided by `T`. |
| 245 | + |
| 246 | + |
| 247 | + |
| 248 | +## Examples |
| 249 | + The following example creates a collection that contains elements of the `Box` type and then searches it for a box matching another box by calling the `FindFirst` method, twice. |
| 250 | + |
| 251 | + The first search does not specify any equality comparer, which means `FindFirst` uses <xref:System.Collections.Generic.EqualityComparer%601.Default%2A?displayProperty=nameWithType> to determine equality of boxes. That in turn uses the implementation of the <xref:System.IEquatable%601.Equals%2A?displayProperty=nameWithType> method in the `Box` class. Two boxes are considered equal if their dimensions are the same. |
| 252 | + |
| 253 | + The second search specifies an equality comparer (`BoxEqVolume`) that defines equality by volume. Two boxes are considered equal if their volumes are the same. |
| 254 | + |
| 255 | + :::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/EqualityComparerT/Default/program.cs" interactive="try-dotnet"::: |
| 256 | + :::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/EqualityComparerT/Default/program.vb"::: |
| 257 | +
|
258 | 258 | ]]></format> |
259 | 259 | </remarks> |
260 | 260 | <altmember cref="T:System.Collections.Generic.IEqualityComparer`1" /> |
@@ -327,11 +327,11 @@ In .NET 8 and later versions, we recommend using the <xref:System.Collections.Ge |
327 | 327 | <returns> |
328 | 328 | <see langword="true" /> if the specified objects are equal; otherwise, <see langword="false" />.</returns> |
329 | 329 | <remarks> |
330 | | - <format type="text/markdown"><![CDATA[ |
331 | | - |
332 | | -## Remarks |
333 | | - The <xref:System.Collections.Generic.EqualityComparer%601.Equals%2A> method is reflexive, symmetric, and transitive. That is, it returns `true` if used to compare an object with itself; `true` for two objects `x` and `y` if it is `true` for `y` and `x`; and `true` for two objects `x` and `z` if it is `true` for `x` and `y` and also `true` for `y` and `z`. |
334 | | - |
| 330 | + <format type="text/markdown"><![CDATA[ |
| 331 | + |
| 332 | +## Remarks |
| 333 | + The <xref:System.Collections.Generic.EqualityComparer%601.Equals%2A> method is reflexive, symmetric, and transitive. That is, it returns `true` if used to compare an object with itself; `true` for two objects `x` and `y` if it is `true` for `y` and `x`; and `true` for two objects `x` and `z` if it is `true` for `x` and `y` and also `true` for `y` and `z`. |
| 334 | + |
335 | 335 | ]]></format> |
336 | 336 | </remarks> |
337 | 337 | <block subset="none" type="overrides"> |
@@ -449,13 +449,13 @@ In .NET 8 and later versions, we recommend using the <xref:System.Collections.Ge |
449 | 449 | <returns> |
450 | 450 | <see langword="true" /> if the specified objects are equal; otherwise, <see langword="false" />.</returns> |
451 | 451 | <remarks> |
452 | | - <format type="text/markdown"><![CDATA[ |
453 | | - |
454 | | -## Remarks |
455 | | - This method is a wrapper for the <xref:System.Collections.Generic.EqualityComparer%601.Equals%28%600%2C%600%29> method, so `obj` must be cast to the type specified by the generic argument `T` of the current instance. If it cannot be cast to `T`, an <xref:System.ArgumentException> is thrown. |
456 | | - |
457 | | - Comparing `null` is allowed and does not generate an exception. |
458 | | - |
| 452 | + <format type="text/markdown"><![CDATA[ |
| 453 | + |
| 454 | +## Remarks |
| 455 | + This method is a wrapper for the <xref:System.Collections.Generic.EqualityComparer%601.Equals%28%600%2C%600%29> method, so `obj` must be cast to the type specified by the generic argument `T` of the current instance. If it cannot be cast to `T`, an <xref:System.ArgumentException> is thrown. |
| 456 | + |
| 457 | + Comparing `null` is allowed and does not generate an exception. |
| 458 | + |
459 | 459 | ]]></format> |
460 | 460 | </remarks> |
461 | 461 | <exception cref="T:System.ArgumentException"> |
@@ -509,17 +509,17 @@ In .NET 8 and later versions, we recommend using the <xref:System.Collections.Ge |
509 | 509 | <summary>Returns a hash code for the specified object.</summary> |
510 | 510 | <returns>A hash code for the specified object.</returns> |
511 | 511 | <remarks> |
512 | | - <format type="text/markdown"><![CDATA[ |
513 | | - |
514 | | -## Remarks |
515 | | - This method is a wrapper for the <xref:System.Collections.Generic.EqualityComparer%601.GetHashCode%28%600%29> method, so `obj` must be a type that can be cast to the type specified by the generic type argument `T` of the current instance. |
516 | | - |
| 512 | + <format type="text/markdown"><![CDATA[ |
| 513 | + |
| 514 | +## Remarks |
| 515 | + This method is a wrapper for the <xref:System.Collections.Generic.EqualityComparer%601.GetHashCode%28%600%29> method, so `obj` must be a type that can be cast to the type specified by the generic type argument `T` of the current instance. |
| 516 | + |
517 | 517 | ]]></format> |
518 | 518 | </remarks> |
519 | | - <exception cref="T:System.ArgumentNullException">The type of <paramref name="obj" /> is a reference type and <paramref name="obj" /> is <see langword="null" />. |
520 | | - |
521 | | - -or- |
522 | | - |
| 519 | + <exception cref="T:System.ArgumentNullException">The type of <paramref name="obj" /> is a reference type and <paramref name="obj" /> is <see langword="null" />. |
| 520 | + |
| 521 | + -or- |
| 522 | + |
523 | 523 | <paramref name="obj" /> is of a type that cannot be cast to type <typeparamref name="T" />.</exception> |
524 | 524 | </Docs> |
525 | 525 | </Member> |
|
0 commit comments