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

Kra*_*mer 7 c# linq

我有一个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";
}
Run Code Online (Sandbox Code Playgroud)

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

Hac*_*ese 5

建议您使用.Any().

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