首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在VB.NET中检查字典是否为空?

问如何在VB.NET中检查字典是否为空?
EN

Stack Overflow用户
提问于 2013-11-11 17:45:56
回答 1查看 10.8K关注 0票数 2

我是vb.net新手,在vb.net中做工作流,我需要检查字典是否为空。我声明了一个字典,但没有给它赋值。

当我使用IsNothing()方法时,它给出了对象引用异常。我该怎么检查呢?

代码语言:javascript
复制
Dim CustDicAs New Dictionary(Of String, Integer)
CustDic.IsNothing()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-11 17:53:35

您可以使用Not Is Nothing或IsNot Nothing或通过Visual Basic中的旧IsNothing函数来检查Nothing的变量。

代码语言:javascript
复制
Dim dict As Dictionary(Of String, String)

  1. Not Is Nothing

If Not dict Is Nothing Then‘not nothing End If

  • IsNot Nothing

If dict End Nothing Then‘not nothing End If

If Not IsNothing(dict) Then‘not nothing End If

我不会再在.NET中使用VB6函数IsNothing,因为它引入了不需要的依赖关系,并且出于前面提到的here的原因(它允许值类型,并且总是返回False)。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19903210

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档