gpt4 book ai didi

c# - 当结果为空时 LINQ 返回什么

转载 作者:IT王子 更新时间:2023-10-29 03:28:26 26 4
gpt4 key购买 nike

我有一个关于 LINQ 查询的问题。通常查询返回 IEnumerable<T>类型。如果返回为空,则不确定它是否为空。我不确定以下是否 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();

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

最佳答案

它将返回一个空的枚举。它不会为空。你可以 sleep 的声音:)

关于c# - 当结果为空时 LINQ 返回什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1191919/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com