var customers = new List<BECustomer>();
customers = GetCustomers();
但是我不明白为什么
customers[0] == null
customers.Any()==true
或customers.Count == 1
或customers==null
为假如何检查空客户?
最佳答案
这是有区别的。
您的列表不为null,因为您使用新的List()实例化了它,然后分配了getCustomers()。也许这返回null。
但是列表中的元素可以为null。例如:
customers[0] = null
然后,将数组中的第一个元素设置为null。
总结一下:
if (customers == null)
检查customerzs变量是否指向null
if (customers[0] == null)
检查数组中的第一个元素是否为null
关于c# - 是集合为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5512257/