本文整理汇总了VB.NET中System.Linq.Enumerable.Except方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Enumerable.Except方法的具体用法?VB.NET Enumerable.Except怎么用?VB.NET Enumerable.Except使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了Enumerable.Except方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: numbers1
' Create two arrays of doubles.
Dim numbers1() As Double = { 2.0, 2.0, 2.1, 2.2, 2.3, 2.3, 2.4, 2.5 }
Dim numbers2() As Double = {2.2}
' Select the elements from the first array that are not
' in the second array.
Dim onlyInFirstSet As IEnumerable(Of Double) = numbers1.Except(numbers2)
Dim output As New System.Text.StringBuilder
For Each number As Double In onlyInFirstSet
output.AppendLine(number)
Next
' Display the output.
Console.WriteLine(output.ToString())
输出:
2 2.1 2.3 2.4 2.5
示例2: 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
示例3: fruits1
Dim fruits1() As Product =
{New Product With {.Name = "apple", .Code = 9},
New Product With {.Name = "orange", .Code = 4},
New Product With {.Name = "lemon", .Code = 12}}
Dim fruits2() As Product =
{New Product With {.Name = "apple", .Code = 9}}
' Get all the elements from the first array
' except for the elements from the second array.
Dim except = fruits1.Except(fruits2)
For Each product In except
Console.WriteLine(product.Name & " " & product.Code)
Next
输出:
apple 9 orange 4 lemon 12
示例4: 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
示例5: fruits1
Dim fruits1() As Product =
{New Product With {.Name = "apple", .Code = 9},
New Product With {.Name = "orange", .Code = 4},
New Product With {.Name = "lemon", .Code = 12}}
Dim fruits2() As Product =
{New Product With {.Name = "apple", .Code = 9}}
' Get all the elements from the first array
' except for the elements from the second array.
Dim except = fruits1.Except(fruits2, New ProductComparer())
For Each product In except
Console.WriteLine(product.Name & " " & product.Code)
Next
输出:
orange 4 lemon 12