相关疑难解决方法(0)

当结果为空时,LINQ会返回什么

我有一个关于LINQ查询的问题.通常,查询返回一个IEnumerable<T>类型.如果返回为空,则不确定它是否为null.我不确定如果在结果中找不到任何内容,以下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();
Run Code Online (Sandbox Code Playgroud)

我知道这是一个非常简单的问题,但我暂时没有VS可用.

c# linq

298
推荐指数
7
解决办法
16万
查看次数

标签 统计

c# ×1

linq ×1