最佳答案
我有一个关于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可用。