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/