gpt4 book ai didi

vb.net - 如何在VB.NET中检查字典是否为空?

转载 作者:行者123 更新时间:2023-12-02 21:43:59 24 4
gpt4 key购买 nike

我是 vb.net 新手,在 vb.net 中执行工作流程,我需要检查字典是否为空。我已经声明了一个字典,但没有为其分配任何值。

当我使用 IsNothing() 方法时,它会给出对象引用异常。我该如何检查?

Dim CustDicAs New Dictionary(Of String, Integer)
CustDic.IsNothing()

最佳答案

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

Dim dict As Dictionary(Of String, String)
  1. 没有就是什么

    If Not dict Is Nothing Then
    ' not nothing
    End If
  2. 没什么

    If dict IsNot Nothing Then
    ' not nothing
    End If
  3. IsNothing function( VB)

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

我不会再在 .NET 中使用 VB6 函数 IsNothing,因为它引入了不需要的依赖项,并且出于上述原因 here (它允许值类型并始终返回False)。

关于vb.net - 如何在VB.NET中检查字典是否为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19903210/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com