[英]How to check dictionary is null in VB.NET?
是vb.net的新手,並且在vb.net中進行工作流程,我需要檢查字典是否為空。 我已經聲明了一個字典,但是沒有給它賦任何值。
當我使用IsNothing()
方法時,它給出了對象引用異常。 我該如何檢查?
Dim CustDicAs New Dictionary(Of String, Integer)
CustDic.IsNothing()
使用Not Is Nothing
或IsNot Nothing
或通過Visual Basic中的舊IsNothing
函數檢查變量是否為Nothing
。
Dim dict As Dictionary(Of String, String)
不是沒有
If Not dict Is Nothing Then ' not nothing End If
沒什么
If dict IsNot Nothing Then ' not nothing End If
IsNothing函數( VB)
If Not IsNothing(dict) Then ' not nothing End If
我不會再在.NET中使用VB6函數IsNothing
,因為它引入了不需要的依賴關系,並且出於此處提到的原因(它允許值類型並且總是返回False
)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.