如何调整函数以返回包含传递变量名称的字符串

时间:2015-05-28 11:08:17

标签: vb.net

我编写了一个比较两个Hashsets和返回差异的函数,但我希望返回的数组包含已发送的Hashsets的名称,而不是" 1"和" 2"。

有可能吗? (我的研究说不!) 有没有其他方法可以做类似的事情?

这是我的代码:

Public Function myDiff(ByVal H1 As HashSet(Of String), ByVal H2 As HashSet(Of String))
    Dim In1No2 As New list(Of String)
    Dim In2No1 As New list(Of String)
    In1No2.add("In 1 and not in 2")
    In2No1.add("In 2 and not in 1")
    For Each mVal In H1
        If Not H2.Contains(mVal) Then In1No2.Add(mVal)
    Next
    For Each mVal In H2
        If Not H1.Contains(mVal) Then In2No1.Add(mVal)
    Next

    Return {In1No2.toarray, In2No1.toarray}
End function

0 个答案:

没有答案