Am new to vb.net and doing a work flow in vb.net, i need to check whether a dictionary is null. I have declared a dictionary, but have not assigned any value to it.
When i use IsNothing()
method it gives object reference exception. How can i check?
Dim CustDicAs New Dictionary(Of String, Integer)
CustDic.IsNothing()
You check variables for Nothing
with Not Is Nothing
or IsNot Nothing
or via the old IsNothing
function from Visual Basic.
Dim dict As Dictionary(Of String, String)
Not Is Nothing
If Not dict Is Nothing Then ' not nothing End If
IsNot Nothing
If dict IsNot Nothing Then ' not nothing End If
If Not IsNothing(dict) Then ' not nothing End If
I wouldn't use the VB6 function IsNothing
in .NET anymore since it introduces unneeded dependencies and for the reason mentioned here (it allows value types and always returns False
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.