我有一个关于 LINQ 查询的问题。通常查询返回一个IEnumerable<T>
类型。如果返回为空,不确定是否为null。我不确定以下是否ToList()
会抛出异常或者只是一个空的List<string>
如果没有发现IEnumerable
result?
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。
它将返回一个空的枚举。它不会为空。你可以睡个好觉了:)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)