LINQ中select和where之间的区别 [英] difference between select and where in LINQ

查看:810
本文介绍了LINQ中select和where之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
Linq:Select和Where之间有什么区别

Possible Duplicate:
Linq: What is the difference between Select and Where

var a = Doc.Document.Where(n => n.Id == id).SingleOrDefault(); 

var b = Doc.Document.Select(n => n.Id == id).SingleOrDefault();

为什么变量b是布尔值?

对不起,我是LINQ的新手.

Sorry about my ignorance, I am new to LINQ.

推荐答案

位置根据谓词过滤一系列值.因此,在第一个示例中,您要从列表中选择功能n.Id == id为true的元素.

Where Filters a sequence of values based on a predicate. So in the first example you are selecting elements from your list where the function n.Id == id is true.

选择投影a的每个元素序列转换为新形式,因此在第二个示例中,您将获得一个布尔值列表,该列表是每个元素上的函数n.Id == id的结果.

Select Projects each element of a sequence into a new form, so in your second example you get a list of booleans which is the result of the function n.Id == id on each element.

这篇关于LINQ中select和where之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆