c# - IsNullOrEmpty 对象

标签 c#

IsNullOrEmpty 与字符串一起使用以检查字符串是否为 null 或空。 是否有一个对象的等价物来查看任何对象是否为空? 我想我们可以做到

    obj1 != null 

但不确定是否有其他方法...

最佳答案

我发现 DataGridViewTextBox 值和一些 JSON 对象不等于 Null,而是 "{}" 值。将它们与 Null 进行比较是行不通的,但使用它们可以解决问题:

if (cell.Value is System.DBNull)

if (cell.Value == System.DBNull.Value)

关于 Null 和 DBNull 之间的区别,我发现了一个很好的摘录:

Do not confuse the notion of null in an object-oriented programming language with a DBNull object. In an object-oriented programming language, null means the absence of a reference to an object. DBNull represents an uninitialized variant or nonexistent database column.

您可以了解有关 DBNull class here 的更多信息.

关于c# - IsNullOrEmpty 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8887570/

相关文章:

c# - ORA-01006 : bind variable does not exist ASP. 网络

c# - yield return 的线程安全性(是吗?)

javascript - 页面上的一个按钮不会调用后面的代码,其他按钮可以

c# - 如何在网络应用程序(mvc/asp.net)中实现视频聊天?

c# - 如何确保线程任务正在运行

java - 在线获取 UTC 时间的可靠方法?

c# - 在 Asp.Net Core 3.0 中禁用身份验证以进行开发

c# - 添加新模型时没有 Code First 选项

C# - 不应该的 CS0136

c# - 如何将 ClosedXML 中的货币格式化为数字