即使字符串不相同也进入条件

stepping into condition even if sring is not same

我是 VB.NET 的初学者。我正在遍历一个车辆列表,如果字符串中的数字满足几个条件,我将字符串中的索引添加到另一个列表中。

第一个条件; If Not item.Equals("11652") 即使不为真,仍然进入状态;

等于(),不等于(),Tostring.Equals

Dim cpti = 0

For Each item In Vehicules.Items
    If ex = 1 Then
        If Not item.Equals("11652") Or item.ToString() <> "11785" Or item.ToString() <> "11814" Or item.ToString() <> "11852" Or item.ToString() <> "11853" Then
            list.Add(cpti)
        End If             

        If item.ToString() = "530011" Or item.ToString() = "530012" Or item.ToString() = "530013" Or item.ToString() = "530014" Or item.ToString() = "530015" Or item.ToString() = "530016" Or item.ToString() = "530017" Or item.ToString() = "530018" Or item.ToString() = "530019" Or item.ToString() = "530020" Then
            list.Add(cpti)
        End If  
    ElseIf ex = 3 Then
        If item.ToString() <> "326481" Or item.ToString() <> "326483" Or item.ToString() <> "326556" Or item.ToString() <> "326557" Then
            list.Add(cpti)
        End If
    Else
        liste.Add(cpti)
    End If

    cpti = cpti + 1
Next

走这条线

If item <> "11652" Or item <> "11785" Then

这将始终为真。让我们尝试一些例子

item = "1"
If item <> "11652" Or item <> "11785" Then
If True Or True Then ' Both of them are True, go in the If

item = "11652"
If item <> "11652" Or item <> "11785" Then
If False Or True Then ' One of them is true, go in the If

item = "11785"
If item <> "11652" Or item <> "11785" Then
If True Or False Then ' One of them is true, go in the If

您可能想要使用 AND 而不是 OR。但是我不知道你想做的背后的逻辑,所以我不能直接给你答案。