本文整理汇总了VB.NET中System.Linq.Enumerable.SequenceEqual方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Enumerable.SequenceEqual方法的具体用法?VB.NET Enumerable.SequenceEqual怎么用?VB.NET Enumerable.SequenceEqual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了Enumerable.SequenceEqual方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Pet
Class Pet
Public Name As String
Public Age As Integer
End Class
Sub SequenceEqualEx1()
' Create two Pet objects.
Dim pet1 As New Pet With {.Name = "Turbo", .Age = 2}
Dim pet2 As New Pet With {.Name = "Peanut", .Age = 8}
' Create two lists of pets.
Dim pets1 As New List(Of Pet)(New Pet() {pet1, pet2})
Dim pets2 As New List(Of Pet)(New Pet() {pet1, pet2})
'Determine if the two lists are equal.
Dim equal As Boolean = pets1.SequenceEqual(pets2)
' Display the output.
Dim text As String = IIf(equal, "are", "are not")
Console.WriteLine($"The lists {text} equal.")
End Sub
输出:
The lists are equal.
示例2: List
' Create two Pet objects.
Dim pet1 As New Pet With {.Name = "Turbo", .Age = 2}
Dim pet2 As New Pet With {.Name = "Peanut", .Age = 8}
' Create two lists of pets.
Dim pets1 As New List(Of Pet)()
pets1.Add(pet1)
pets1.Add(pet2)
Dim pets2 As New List(Of Pet)()
pets2.Add(New Pet With {.Name = "Turbo", .Age = 2})
pets2.Add(New Pet With {.Name = "Peanut", .Age = 8})
' Determine if the two lists are equal.
Dim equal As Boolean = pets1.SequenceEqual(pets2)
' Display the output.
Dim text As String = IIf(equal, "are", "are not")
Console.WriteLine($"The lists {text} equal.")
输出:
The lists are not equal.
示例3: IEquatable
Public Class ProductA
Inherits IEquatable(Of ProductA)
Public Property Name As String
Public Property Code As Integer
Public Function Equals(ByVal other As ProductA) As Boolean
If other Is Nothing Then Return False
Return Me.Name = other.Name AndAlso Me.Code = other.Code
End Function
Public Overrides Function Equals(ByVal obj As Object) As Boolean
Return Equals(TryCast(obj, ProductA))
End Function
Public Overrides Function GetHashCode() As Integer
Return (Name, Code).GetHashCode()
End Function
End Class
示例4: storeA
Dim storeA() As Product =
{New Product With {.Name = "apple", .Code = 9},
New Product With {.Name = "orange", .Code = 4}}
Dim storeB() As Product =
{New Product With {.Name = "apple", .Code = 9},
New Product With {.Name = "orange", .Code = 4}}
Dim equalAB = storeA.SequenceEqual(storeB)
Console.WriteLine("Equal? " & equalAB)
输出:
Equal? True
示例5: IEqualityComparer
Public Class Product
Public Property Name As String
Public Property Code As Integer
End Class
' Custom comparer for the Product class
Public Class ProductComparer
Implements IEqualityComparer(Of Product)
Public Function Equals1(
ByVal x As Product,
ByVal y As Product
) As Boolean Implements IEqualityComparer(Of Product).Equals
' Check whether the compared objects reference the same data.
If x Is y Then Return True
'Check whether any of the compared objects is null.
If x Is Nothing OrElse y Is Nothing Then Return False
' Check whether the products' properties are equal.
Return (x.Code = y.Code) AndAlso (x.Name = y.Name)
End Function
Public Function GetHashCode1(
ByVal product As Product
) As Integer Implements IEqualityComparer(Of Product).GetHashCode
' Check whether the object is null.
If product Is Nothing Then Return 0
' Get hash code for the Name field if it is not null.
Dim hashProductName =
If(product.Name Is Nothing, 0, product.Name.GetHashCode())
' Get hash code for the Code field.
Dim hashProductCode = product.Code.GetHashCode()
' Calculate the hash code for the product.
Return hashProductName Xor hashProductCode
End Function
End Class
示例6: storeA
Dim storeA() As Product =
{New Product With {.Name = "apple", .Code = 9},
New Product With {.Name = "orange", .Code = 4}}
Dim storeB() As Product =
{New Product With {.Name = "apple", .Code = 9},
New Product With {.Name = "orange", .Code = 4}}
Dim equalAB = storeA.SequenceEqual(storeB, New ProductComparer())
Console.WriteLine("Equal? " & equalAB)
输出:
Equal? True