当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET Enumerable.Intersect方法代码示例

本文整理汇总了VB.NET中System.Linq.Enumerable.Intersect方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Enumerable.Intersect方法的具体用法?VB.NET Enumerable.Intersect怎么用?VB.NET Enumerable.Intersect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。


在下文中一共展示了Enumerable.Intersect方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: 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
开发者ID:VB.NET开发者,项目名称:System.Linq,代码行数:42,代码来源:Enumerable.Intersect

示例2: store1

Dim store1() As Product = 
    {New Product With {.Name = "apple", .Code = 9}, 
     New Product With {.Name = "orange", .Code = 4}}

Dim store2() As Product = 
    {New Product With {.Name = "apple", .Code = 9}, 
     New Product With {.Name = "lemon", .Code = 12}}
开发者ID:VB.NET开发者,项目名称:System.Linq,代码行数:7,代码来源:Enumerable.Intersect

示例3: ProductComparer

' Get the products from the first array 
' that have duplicates in the second array.

Dim duplicates = store1.Intersect(store2, New ProductComparer())

For Each product In duplicates
    Console.WriteLine(product.Name & " " & product.Code)
Next
开发者ID:VB.NET开发者,项目名称:System.Linq,代码行数:8,代码来源:Enumerable.Intersect

输出:

apple 9

示例4: id1

' Create two integer arrays.
Dim id1() As Integer = {44, 26, 92, 30, 71, 38}
Dim id2() As Integer = {39, 59, 83, 47, 26, 4, 30}

' Find the set intersection of the two arrays.
Dim intersection As IEnumerable(Of Integer) = id1.Intersect(id2)

Dim output As New System.Text.StringBuilder
For Each id As Integer In intersection
    output.AppendLine(id)
Next

' Display the output.
Console.WriteLine(output.ToString)
开发者ID:VB.NET开发者,项目名称:System.Linq,代码行数:14,代码来源:Enumerable.Intersect

输出:

26
30

示例5: 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
开发者ID:VB.NET开发者,项目名称:System.Linq,代码行数:20,代码来源:Enumerable.Intersect

示例6: store1

Dim store1() As ProductA = 
    {New Product With {.Name = "apple", .Code = 9}, 
     New Product With {.Name = "orange", .Code = 4}}

Dim store2() As ProductA = 
    {New Product With {.Name = "apple", .Code = 9}, 
     New Product With {.Name = "lemon", .Code = 12}}
开发者ID:VB.NET开发者,项目名称:System.Linq,代码行数:7,代码来源:Enumerable.Intersect

示例7:

' Get the products from the first array 
' that have duplicates in the second array.

Dim duplicates = store1.Intersect(store2)

For Each product In duplicates
    Console.WriteLine(product.Name & " " & product.Code)
Next
开发者ID:VB.NET开发者,项目名称:System.Linq,代码行数:8,代码来源:Enumerable.Intersect

输出:

apple 9


注:本文中的System.Linq.Enumerable.Intersect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。