0

根据调试器,我有一个名为myCancelledNewtonsoft.Json.Linq.Jtoken 类型的变量,其值为 Nothing。我还将它转换为 Object 并且所有这些条件都失败了。我的问题很简单:如何检查它是否为 Nothing/Null/False/Empty?

这是我尝试过的。这些条件都不为真:

            If myCancelled Is Nothing Then
                'Doesn't come here
            End If
            If myCancelled = DBNull.Value.ToString Then
                'Doesn't come here
            End If
            If myCancelled = "null" Then
                'Doesn't come here
            End If
            If IsDBNull(myCancelled) Then
                'Doesn't come here
            End If
            If myCancelled Is DBNull.Value Then
                'Doesn't come here
            End If
            If String.IsNullOrEmpty(myCancelled) = True Then
                'Doesn't come here
            End If
            If myCancelled.ToString = "Nothing" Then
                'Runtime error
            End If
            If myCancelled = DBNull.Value Then
                'Runtime error
            End If
            If IsNothing(myCancelled) Then
                'Doesn't come here
            End If

我是 VB.net 的新手,因此不胜感激。

编辑

这个有效,但它让误报通过(当 myCancelled 有它的值时,条件为真)

            If Not myCancelled Then
                ' It comes here
            End If
4

1 回答 1

1

这是有效的。当你习惯了 Java、C# 等时,VB 就很难学了。

If Not myCancelled.Equals("Y") Then
    ' It finally came here
End If
于 2015-12-23T20:32:08.500 回答