【发布时间】:2009-07-28 04:19:02
【问题描述】:
我有一个关于 LINQ 查询的问题。通常一个查询返回一个IEnumerable<T> 类型。如果返回为空,则不确定是否为空。如果在IEnumerable 结果中找不到任何内容,我不确定以下ToList() 是否会抛出异常或只是一个空的List<string>?
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可用。
【问题讨论】:
-
我猜结果是 Enumerable.Empty?