本文整理匯總了VB.NET中System.Collections.IStructuralEquatable.Equals方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET IStructuralEquatable.Equals方法的具體用法?VB.NET IStructuralEquatable.Equals怎麽用?VB.NET IStructuralEquatable.Equals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Collections.IStructuralEquatable
的用法示例。
在下文中一共展示了IStructuralEquatable.Equals方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Equals
' 導入命名空間
Imports System.Collections
Imports System.Collections.Generic
Public Class NanComparer : Implements IEqualityComparer
Public Overloads Function Equals(x As Object, y As Object) As Boolean _
Implements IEqualityComparer.Equals
If TypeOf x Is Single Then
Return CSng(x) = CSng(y)
ElseIf TypeOf x Is Double Then
Return CDbl(x) = CDbl(y)
Else
Return EqualityComparer(Of Object).Default.Equals(x, y)
End If
End Function
Public Overloads Function GetHashCode(obj As Object) As Integer _
Implements IEqualityComparer.GetHashCode
Return EqualityComparer(Of Object).Default.GetHashCode(obj)
End Function
End Class
示例2: Example
Module Example
Public Sub Main()
Dim t1 = Tuple.Create(12.3, Double.NaN, 16.4)
Dim t2 = Tuple.Create(12.3, Double.NaN, 16.4)
' Call default Equals method.
Console.WriteLine(t1.Equals(t2))
Dim equ As IStructuralEquatable = t1
' Call IStructuralEquatable.Equals using default comparer.
Console.WriteLine(equ.Equals(t2, EqualityComparer(Of Object).Default))
' Call IStructuralEquatable.Equals using
' StructuralComparisons.StructuralEqualityComparer.
Console.WriteLine(equ.Equals(t2,
StructuralComparisons.StructuralEqualityComparer))
' Call IStructuralEquatable.Equals using custom comparer.
Console.WriteLine(equ.Equals(t2, New NanComparer))
End Sub
End Module
輸出:
True True True False