Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion xml/System.Collections.Generic/Comparer`1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
## Examples
The following example derives a class, `BoxLengthFirst`, from the <xref:System.Collections.Generic.Comparer%601> class. This comparer compares two objects of type `Box`. It sorts them first by length, then by height, and then by width. The `Box` class implements the <xref:System.IComparable%601> interface to control the default comparison between two `Box` objects. This default implementation sorts first by height, then by length, and then by width. The example shows the differences between the two comparisons by sorting a list of `Box` objects first by using the `BoxLengthFirst` comparer and then by using the default comparer.

:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/ComparerT/Overview/program.cs" interactive="try-dotnet" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/ComparerT/Overview/program.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/ComparerT/Overview/program.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/ComparerT/Overview/program.vb" id="Snippet1":::

Expand Down
10 changes: 5 additions & 5 deletions xml/System.Collections.Generic/Dictionary`2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@
## Examples
The following code example shows how to use the <xref:System.Collections.Generic.Dictionary%602.%23ctor%28System.Collections.Generic.IEqualityComparer%7B%600%7D%29> constructor to initialize a <xref:System.Collections.Generic.Dictionary%602> with sorted content from another dictionary. The code example creates a <xref:System.Collections.Generic.SortedDictionary%602> and populates it with data in random order, then passes the <xref:System.Collections.Generic.SortedDictionary%602> to the <xref:System.Collections.Generic.Dictionary%602.%23ctor%28System.Collections.Generic.IEqualityComparer%7B%600%7D%29> constructor, creating a <xref:System.Collections.Generic.Dictionary%602> that is sorted. This is useful if you need to build a sorted dictionary that at some point becomes static; copying the data from a <xref:System.Collections.Generic.SortedDictionary%602> to a <xref:System.Collections.Generic.Dictionary%602> improves retrieval speed.

:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source.cs" interactive="try-dotnet" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source.vb" id="Snippet1":::

Expand Down Expand Up @@ -455,7 +455,7 @@
## Examples
The following code example creates a <xref:System.Collections.Generic.Dictionary%602> with a case-insensitive equality comparer for the current culture. The example adds four elements, some with lower-case keys and some with upper-case keys. The example then attempts to add an element with a key that differs from an existing key only by case, catches the resulting exception, and displays an error message. Finally, the example displays the elements in the dictionary.

:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source2.cs" interactive="try-dotnet" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source2.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source2.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source2.vb" id="Snippet1":::

Expand Down Expand Up @@ -524,7 +524,7 @@
## Examples
The following code example creates a dictionary with an initial capacity of 4 and populates it with 4 entries.

:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source3.cs" interactive="try-dotnet" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source3.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source3.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source3.vb" id="Snippet1":::

Expand Down Expand Up @@ -610,7 +610,7 @@
> [!NOTE]
> When you create a new dictionary with a case-insensitive comparer and populate it with entries from a dictionary that uses a case-sensitive comparer, as in this example, an exception occurs if the input dictionary has keys that differ only by case.

:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source1.cs" interactive="try-dotnet" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source1.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source1.vb" id="Snippet1":::

Expand Down Expand Up @@ -753,7 +753,7 @@
## Examples
The following code example creates a <xref:System.Collections.Generic.Dictionary%602> with an initial capacity of 5 and a case-insensitive equality comparer for the current culture. The example adds four elements, some with lower-case keys and some with upper-case keys. The example then attempts to add an element with a key that differs from an existing key only by case, catches the resulting exception, and displays an error message. Finally, the example displays the elements in the dictionary.

:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source4.cs" interactive="try-dotnet" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source4.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source4.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/DictionaryTKey,TValue/.ctor/source4.vb" id="Snippet1":::

Expand Down
114 changes: 57 additions & 57 deletions xml/System.Collections.Generic/EqualityComparer`1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,24 @@
<typeparam name="T">The type of objects to compare.</typeparam>
<summary>Provides a base class for implementations of the <see cref="T:System.Collections.Generic.IEqualityComparer`1" /> generic interface.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
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>.
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`.
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.
## Examples
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.
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.
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/EqualityComparerT/Overview/program.cs" interactive="try-dotnet" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/EqualityComparerT/Overview/program.vb" id="Snippet1":::
<format type="text/markdown"><![CDATA[

## Remarks

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>.

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`.

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.

## Examples
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.

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.

:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/EqualityComparerT/Overview/program.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/EqualityComparerT/Overview/program.vb" id="Snippet1":::

]]></format>
</remarks>
<altmember cref="T:System.Collections.Generic.IEqualityComparer`1" />
Expand Down Expand Up @@ -180,7 +180,7 @@ In .NET 8 and later versions, we recommend using the <xref:System.Collections.Ge
</Parameters>
<Docs>
<param name="equals">The delegate to use to implement the <see cref="M:System.Collections.Generic.EqualityComparer`1.Equals(`0,`0)" /> method.</param>
<param name="getHashCode">The delegate to use to implement the <see cref="M:System.Collections.Generic.EqualityComparer`1.GetHashCode(`0)" /> method.
<param name="getHashCode">The delegate to use to implement the <see cref="M:System.Collections.Generic.EqualityComparer`1.GetHashCode(`0)" /> method.
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>
<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>
<returns>The new comparer.</returns>
Expand Down Expand Up @@ -238,23 +238,23 @@ In .NET 8 and later versions, we recommend using the <xref:System.Collections.Ge
<summary>Returns a default equality comparer for the type specified by the generic argument.</summary>
<value>The default instance of the <see cref="T:System.Collections.Generic.EqualityComparer`1" /> class for type <typeparamref name="T" />.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
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`.
## Examples
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.
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.
The second search specifies an equality comparer (`BoxEqVolume`) that defines equality by volume. Two boxes are considered equal if their volumes are the same.
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/EqualityComparerT/Default/program.cs" interactive="try-dotnet":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/EqualityComparerT/Default/program.vb":::
<format type="text/markdown"><![CDATA[

## Remarks
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`.



## Examples
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.

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.

The second search specifies an equality comparer (`BoxEqVolume`) that defines equality by volume. Two boxes are considered equal if their volumes are the same.

:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/EqualityComparerT/Default/program.cs" interactive="try-dotnet":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/EqualityComparerT/Default/program.vb":::

]]></format>
</remarks>
<altmember cref="T:System.Collections.Generic.IEqualityComparer`1" />
Expand Down Expand Up @@ -327,11 +327,11 @@ In .NET 8 and later versions, we recommend using the <xref:System.Collections.Ge
<returns>
<see langword="true" /> if the specified objects are equal; otherwise, <see langword="false" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
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`.
<format type="text/markdown"><![CDATA[

## Remarks
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`.

]]></format>
</remarks>
<block subset="none" type="overrides">
Expand Down Expand Up @@ -449,13 +449,13 @@ In .NET 8 and later versions, we recommend using the <xref:System.Collections.Ge
<returns>
<see langword="true" /> if the specified objects are equal; otherwise, <see langword="false" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
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.
Comparing `null` is allowed and does not generate an exception.
<format type="text/markdown"><![CDATA[

## Remarks
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.

Comparing `null` is allowed and does not generate an exception.

]]></format>
</remarks>
<exception cref="T:System.ArgumentException">
Expand Down Expand Up @@ -509,17 +509,17 @@ In .NET 8 and later versions, we recommend using the <xref:System.Collections.Ge
<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
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.
<format type="text/markdown"><![CDATA[

## Remarks
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.

]]></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" />.
-or-
<exception cref="T:System.ArgumentNullException">The type of <paramref name="obj" /> is a reference type and <paramref name="obj" /> is <see langword="null" />.

-or-

<paramref name="obj" /> is of a type that cannot be cast to type <typeparamref name="T" />.</exception>
</Docs>
</Member>
Expand Down
2 changes: 1 addition & 1 deletion xml/System.Collections.Generic/ICollection`1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

This example also implements an <xref:System.Collections.Generic.IEnumerator%601> interface for the `BoxCollection` class so that the collection can be enumerated.

:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/ICollectionT/Overview/program.cs" interactive="try-dotnet" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.Collections.Generic/ICollectionT/Overview/program.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/System.Collections.Generic/ICollectionT/Overview/program.vb" id="Snippet1":::

]]></format>
Expand Down
Loading