Search code examples
.netvb.netarrays.net-2.0

Compare two arrays with different dimension


I am trying to compare two arrays that always have different dimensions.

eg. arr1 -> {1,2,3} and arr2->{1,2}

I did try and able to get the matching items to new array. But I am expecting to get the unmatched items only

I am expecting to compare both arrays and put only the item '3' to a new array which is in arr1 and not in arr2

eg arr1 -> {1,2,3} and arr2->{1,2} should result a new array with 3 arr1 -> {1,2,3,4} and arr2->{1,2} should result a array with 3,4

Is there any way of doing this for older version of .net framework without using Enumerable.Except


Solution

  • I have done something like this. if we have two arrays called paramOld{"1","2","3"} and paramNew{"2","3"}

    If paramOld.Length > paramNew.Length Then
                Dim paramDelete((paramOld.Length - paramNew.Length) - 1) As String
    
    
                Dim isFound As Boolean = False
                For i As Int32 = 0 To oldparamLenght - 1
                    isFound = False
                    For j As Int32 = 0 To newparamLength - 1
                        If paramOld(i) = paramNew(j) Then
                            isFound = True
                            Exit For
                        End If
                    Next
                    If isFound = False Then
                        paramDelete(i) = paramOld(i)
                    End If
                Next
    End If