根据Debugger的说法,我得到了一个名为myCancelled
的变量,类型为Newtonsoft.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
答案 0 :(得分:1)
这是有效的。当你习惯了Java,C#等时,VB很难学习。
If Not myCancelled.Equals("Y") Then
' It finally came here
End If