本文整理汇总了VB.NET中System.Tuple<T1,T2>.IStructuralEquatable.Equals方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Tuple<T1,T2>.IStructuralEquatable.Equals方法的具体用法?VB.NET Tuple<T1,T2>.IStructuralEquatable.Equals怎么用?VB.NET Tuple<T1,T2>.IStructuralEquatable.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Tuple<T1,T2>
的用法示例。
在下文中一共展示了Tuple<T1,T2>.IStructuralEquatable.Equals方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
' 导入命名空间
Imports System.Collections
Public Class Item2Comparer(Of T1, T2) : Implements IEqualityComparer
Public Overloads Function Equals(x As Object, y As Object) As Boolean _
Implements IEqualityComparer.Equals
' Return true for all values of Item1.
If TypeOf x Is T1 Then
Return True
Else
Return x.Equals(y)
End If
End Function
Public Overloads Function GetHashCode(obj As Object) As Integer _
Implements IEqualityComparer.GetHashCode
If TypeOf obj Is T1 Then
Return CType(obj, T1).GetHashCode()
Else
Return CType(obj, T2).GetHashCode()
End If
End Function
End Class
Module Example
Public Sub Main()
Dim distancesWalked() = {
Tuple.Create("Jan", Double.NaN),
Tuple.Create("Joe", Double.NaN),
Tuple.Create("Adam", 1.36),
Tuple.Create("Selena", 2.01),
Tuple.Create("Jake", 1.36) }
For ctr As Integer = 0 To distancesWalked.Length - 1
Dim distanceWalked As Tuple(Of String, Double) = distancesWalked(ctr)
For ctr2 As Integer = ctr + 1 To distancesWalked.Length - 1
Console.WriteLine("{0} = {1}: {2}", distanceWalked,
distancesWalked(ctr2),
DirectCast(distanceWalked, IStructuralEquatable).Equals(distancesWalked(ctr2),
new Item2Comparer(Of String, Double)))
Next
Console.WriteLine()
Next
End Sub
End Module
输出:
(Jan, NaN) = (Joe, NaN): True (Jan, NaN) = (Adam, 1.36): False (Jan, NaN) = (Selena, 2.01): False (Jan, NaN) = (Jake, 1.36): False (Joe, NaN) = (Adam, 1.36): False (Joe, NaN) = (Selena, 2.01): False (Joe, NaN) = (Jake, 1.36): False (Adam, 1.36) = (Selena, 2.01): False (Adam, 1.36) = (Jake, 1.36): True (Selena, 2.01) = (Jake, 1.36): False