Foxtable(狐表)用户栏目专家坐堂 → 如何判断两个集合中元素是否相等,不相等输出那个不相等的值


  共有2710人关注过本帖树形打印复制链接

主题:如何判断两个集合中元素是否相等,不相等输出那个不相等的值

帅哥哟,离线,有人找我吗?
Hyphen
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:5015 积分:25363 威望:0 精华:0 注册:2015/8/18 9:21:00
  发帖心情 Post By:2015/9/5 11:32:00 [显示全部帖子]

Dim v1() As String = {"中国","美国","英国","俄罗斯"}
Dim s1 As New List(of String)
Dim s2 As New List(of String)
s1.AddRange(v1)
s2.AddRange(s1)
s2(2) = "法国"


Dim cou As Integer = s1.Count - 1

If s1.Count <> s2.Count Then
    If s1.Count > s2.Count Then
        cou = s2.Count - 1
        msgbox("s1比s2多" & s1.Count - s2.Count & "个元素")
    Else
        msgbox("s2比s1多" & s2.Count - s1.Count & "个元素")
        
    End If
End If

For i As Integer = 0 To cou
    If s2(i) <>  s1(i) Then
        msgbox("第" & i+1 & "个元素值不同:" & vbcrlf & "s1:" & s1(i) & "s2:" & s2(i))
    End If
Next

 回到顶部