【发布时间】:2017-04-11 08:21:16
【问题描述】:
我已经简化了一段延迟执行代码,但是如果不将其包装在 try/catch 中,您究竟如何检查以下内容是否为空/空?
string[] nullCollection = null;
IEnumerable<string> ienumerable = new[] { nullCollection }.SelectMany(a => a);
bool isnull = ienumerable == null; //returns false
bool isany = ienumerable.Any(); //throws an exception
【问题讨论】:
-
@MrinalKamboj 这是一个 NullReferenceException 抛出,因为 SelectManyIterator 是用一个空元素调用的。
-
@RB。那么它很棘手,我以上几点都不成立
标签: c# linq ienumerable