以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  请教集合的比较方法  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=48814)

--  作者:rjh4078
--  发布时间:2014/4/5 22:54:00
--  请教集合的比较方法

有A B两个类型相同的集合 如何找出两个集合中不同的值?

比如A:{1,2,3,4,5}

    B:{2,3,5}

它们的不同值是{1,4}


--  作者:y2287958
--  发布时间:2014/4/6 7:21:00
--  
循环比较呗
--  作者:lsy
--  发布时间:2014/4/6 8:28:00
--  
Dim int1() As Integer = {1,2,3,4,5}
Dim int2() As Integer = {2,3,5,6}
Dim lst,lst1,lst2 As New List(Of Integer)
lst1.AddRange(Int1)
lst2.AddRange(Int2)
For Each i As Integer In lst1
    If lst.Contains(i) = False Then
        lst.Add(i)
    End If
    For Each j As Integer In lst2
        If lst.Contains(j) Then
            lst.Remove(j)
        End If
        If lst.Contains(j) = False AndAlso lst1.Contains(j) = False Then
            lst.Add(j)
        End If
    Next
Next
For Each i As Integer In lst
    Output.Show(i)
Next

--  作者:rjh4078
--  发布时间:2014/4/6 10:03:00
--  
谢谢 lsy