且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何避免vb6集合中的重复值

更新时间:2023-11-27 11:04:34

创建循环并在循环中向集合添加数据。

然后检查是否收集包含值显示错误,

否则将数据添加到您的收藏中..



Create a loop and add data to your collection in the loop.
Then check if collection contains value show error,
Else add data to your collection..

For Each input As var In inputList
    If OrdLines.Any(() => {  }, str.Item1.Contains(firstinputvalue)) Then
        ' show error
    Else
        OrdLines.Add(input)
    End If
Next


您可以检查ordlines是否包含您要添加的值



You could check if the ordlines contains the values you want to add

If OrdLines.Contains(555) Or OrdLines.Contains("This is the fifth item") Then
           MessageBox.Show("One of these items allready excists")
       Else
           OrdLines.Add(555, "This is the fifth item")
       End If





但是当您想要添加的值是5555时,您会有一个消息框

显示该值已经存在。



为了避免你可以使用等于并检查列表中的每个值





But when the value you want to add is 5555 then you would have a messagebox
showing that the value already excists.

To avoid that you could use an equals and check every value in your list

For Each item In OrdLines
          If item.Equals(555) Then
              MessageBox.Show("555")
          ElseIf Not item.Equals(555) Then
              OrdLines.Add(555, "This is the fifth item")
          End If
      Next