什么是LINQ返回时,结果是空的 [英] What does LINQ return when the results are empty
本文介绍了什么是LINQ返回时,结果是空的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个关于LINQ查询问题。正常情况下,查询返回IEnumerable的类型。如果返回是空的,不知道这是否是空或不是。我不知道如果下面了ToList()将抛出一个异常,或者只是一个空List<串GT;如果没有在IEnumerable的结果,发现了什么?
I have a question about LINQ query. Normally a query returns a IEnumerable type. If the return is empty, not sure if it is null or not. I am not sure if the following ToList() will throw an exception or just a empty List<string> if nothing found in 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可暂且。
I know it is a very simple question, but I don't have VS available for the time being.
推荐答案
它会返回一个空的枚举。它不会为null。你可以睡的声音:)
It will return an empty enumerable. It wont be null. You can sleep sound :)
这篇关于什么是LINQ返回时,结果是空的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文