如何检查对象是否为空? [英] How to check if an object is null?
本文介绍了如何检查对象是否为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,我有一个班级数组:
Hey I have an array of class:
Empty = new EmptyPage[100];
for (int i = 0; i < 100; i++)
Empty[i] = null;
如果我这样做:if(Empty [0] == null) ==>总是返回false;
检查对象是否未定义或者为空的最佳方法是什么?
If I do: if(Empty[0]==null) ==> always returns false;
What is the best way to check if an object is not defined or it is null?
推荐答案
你的代码看起来不错。
要检查null
,您可以随时查看null coalese
运营商 [ ^ ]。
Your code looks ok.
To check fornull
you can always look at thenull coalese
operator[^].
申请等等
apply If Else
if(Empty[i].Equals(null))
{
}
这篇关于如何检查对象是否为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文