如何获得两个二维数组之间的交集?

时间:2015-03-23 15:48:09

标签: arrays vb.net multidimensional-array intersection

我希望获得两个二维数组之间的交集,并将其作为二维数组返回,如下所示:...

Private Function GetIntersection(ByVal Array2D1 As String(,), ByVal Array2D2 As String(,)) As String(,)

1 个答案:

答案 0 :(得分:0)

Public Class Pair : Implements IEquatable(Of Pair) 'Defines a generalized method that a value type or class implements to create a type-specific method for determining equality of instances.
'the Pair values to compare
Public Report As String
Public Match As String

'Indicates whether the current object is equal to another object of the same type.
Public Function Equals1(p As Pair) As Boolean Implements IEquatable(Of Pair).Equals
    Return Report = p.Report And Match = p.Match
End Function

'A hash code intended for efficient lookup in collections that are based on a hash table.
Public Overrides Function GetHashCode() As Integer
    Dim hashReport = Report.GetHashCode()
    Dim hashMatch = Match.GetHashCode()
    Return hashReport Xor hashMatch
End Function

结束班

 Private Function GetIntersection(ByVal one As List(Of Pair), ByVal second As List(Of Pair)) As List(Of Pair)
    Dim intersection As New List(Of Pair)

    If second.Count = 0 Then
        second = one
    End If
    intersection = one.Intersect(second).ToList
    Return intersection
End Function