比较具有不同维数的两个数组 [英] 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
我希望比较两个数组,仅将项目'3'放到arr1而不是arr2的新数组中
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
例如arr1-> {1,2,3}和arr2-> {1,2}应产生一个包含3的新数组 arr1-> {1,2,3,4}和arr2-> {1,2}应该得到3,4的数组
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
推荐答案
我已经做了类似的事情.
如果我们有两个分别称为paramOld
{"1","2","3"}和paramNew
{"2","3"}
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
这篇关于比较具有不同维数的两个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!