Skip to content

Commit e7e6019

Browse files
he-devRon Petrusha
authored andcommitted
Update IStructuralEquatable.xml (#3028)
* Update IStructuralEquatable.xml We read that > The following example defines a NanComparer class that implements the IStructuralEquatable interface. but the code implements a different interface ```c# class NanComparer : IEqualityComparer ``` `IStructuralEquatable` is implemented by the tuple. `NanComparer` is used as a parmeter in the third example. * Update IStructuralEquatable.xml * Update IStructuralEquatable.xml
1 parent 9c734f4 commit e7e6019

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

xml/System.Collections/IStructuralEquatable.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@
4242
4343
4444
45-
## Examples
46-
The default equality comparer, `EqualityComparer<Object>.Default.Equals`, considers two `NaN` values to be equal. However, in some cases, you may want the comparison of `NaN` values for equality to return `false`, which indicates that the values cannot be compared. The following example defines a `NanComparer` class that implements the <xref:System.Collections.IStructuralEquatable> interface. It compares two <xref:System.Double> or two <xref:System.Single> values by using the equality operator. It passes values of any other type to the default equality comparer.
45+
## Examples
46+
47+
The default equality comparer, `EqualityComparer<Object>.Default.Equals`, considers two `NaN` values to be equal. However, in some cases, you may want the comparison of `NaN` values for equality to return `false`, which indicates that the values cannot be compared. The following example defines a `NanComparer` class that implements the <xref:System.Collections.IEqualityComparer> interface. It is used by the third example as an argument to the <xref:System.Collections.IStructuralEquatable.Equals(System.Object,System.Collections.IEqualityComparer)> method of the <xref:System.Collections.IStructuralEquatable> interface that tuples implement. It compares two <xref:System.Double> or two <xref:System.Single> values by using the equality operator. It passes values of any other type to the default equality comparer.
4748
48-
[!code-csharp[System.Collections.IStructuralEquatable#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.collections.istructuralequatable/cs/nanexample1.cs#1)]
49-
[!code-vb[System.Collections.IStructuralEquatable#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.collections.istructuralequatable/vb/nanexample1.vb#1)]
49+
[!code-csharp[System.Collections.IStructuralEquatable#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.collections.istructuralequatable/cs/nanexample1.cs#1)]
50+
[!code-vb[System.Collections.IStructuralEquatable#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.collections.istructuralequatable/vb/nanexample1.vb#1)]
5051
5152
The following example creates two identical 3-tuple objects whose components consist of three <xref:System.Double> values. The value of the second component is <xref:System.Double.NaN?displayProperty=nameWithType>. The example then calls the <xref:System.Tuple%603.Equals%2A?displayProperty=nameWithType> method, and it calls the <xref:System.Collections.IStructuralEquatable.Equals%2A?displayProperty=nameWithType> method three times. The first time, it passes the default equality comparer that is returned by the <xref:System.Collections.Generic.EqualityComparer%601.Default%2A?displayProperty=nameWithType> property. The second time, it passes the default equality comparer that is returned by the <xref:System.Collections.StructuralComparisons.StructuralEqualityComparer%2A?displayProperty=nameWithType> property. The third time, it passes the custom `NanComparer` object. As the output from the example shows, the first three method calls return `true`, whereas the fourth call returns `false`.
5253

0 commit comments

Comments
 (0)