Foxtable(狐表)用户栏目专家坐堂 → 请教集合


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

主题:请教集合

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


加好友 发短信
等级:二尾狐 帖子:574 积分:4252 威望:0 精华:0 注册:2015/5/13 8:32:00
  发帖心情 Post By:2018/11/16 9:33:00 [显示全部帖子]

Dim jh1 As New List(Of String)
Dim jh2 As New List(Of String)
For i As Integer = 0 To 10
    jh1.Add("cs" & i)
    jh2.Add("cs" & i)
Next
If jh1.Count<> jh2.Count Then Return "集合数量不同!"

'查询2个集合内容 是否一样!
Dim lszd1 As new Dictionary(of String,Integer)
For Each s As String In jh1
    If lszd1.ContainsKey(s)=False Then
        lszd1.Add(s,0)
    Else
        lszd1(s)+=1
    End If
Next

Dim lszd2 As new Dictionary(of String,Integer)
For Each s As String In jh2
    If lszd2.ContainsKey(s)=False Then
        lszd2.Add(s,0)
    Else
        lszd2(s)+=1
    End If
Next

If lszd1.Count<>lszd2.Count Then Return "内容不一样1!"
For Each s As String In lszd1.Keys
    If lszd2.ContainsKey(s)=False Then Return "内容不一样2"
    If lszd2(s)<>lszd1(s) Then Return "内容不一样3"
Next

 

'顺序必须一样则转换一下!

Dim str1 As String = String.Join(",",jh1.ToArray)
Dim str2 As String = String.Join(",",jh2.ToArray)
output.show(str1 & "  " & str2 )
If String.Compare(str1, str2, False) Then Return "集合顺序内容不同!"

Return "两个家伙一样"

 

[此贴子已经被作者于2018/11/16 9:33:36编辑过]

 回到顶部