我对LINQ查询有疑问。通常,查询返回一个IEnumerable<T>
类型。如果返回为空,则不确定它是否为空。我不确定以下内容ToList()
是否会引发异常,或者List<string>
如果IEnumerable
结果没有发现,则为空?
List<string> list = {"a"};
// is the result null or something else?
IEnumerable<string> ilist = from x in list where x == "ABC" select x;
// Or directly to a list, exception thrown?
List<string> list1 = (from x in list where x == "ABC" select x).ToList();
我知道这是一个非常简单的问题,但是我暂时没有VS。
它将返回一个空的可枚举。它不会为空。你可以睡觉的声音:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句