gpt4 book ai didi

c# - 确定 null 或计数 0 的最佳方法

转载 作者:太空狗 更新时间:2023-10-29 20:11:11 24 4
gpt4 key购买 nike

我有一个 iQueryable,我需要知道它是 null 还是没有值。

IQueryable<people> L = (from p in people 
where p.lastname.Contains("y")
select p);
if (L != null && L.Count() > 0) {
return "Something";
} else {
return "NOTHING";
}

好吧,如果您使用 L.Count(),它将使用更多资源。有没有更好的办法?不使用 L.Count()

的东西

最佳答案

建议您使用.Any()

IQueryable<people> L = (from p in people 
where p.lastname.Contains("y")
select p);
if (L.Any()) {
return "Something";
} else {
return "NOTHING";
}

关于c# - 确定 null 或计数 0 的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9414805/

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