Linq:Select 和 Where 有什么区别 [英] Linq: What is the difference between Select and Where

查看:51
本文介绍了Linq:Select 和 Where 有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SelectWhere 方法在 Linq 中可用.关于这两种方法,每个开发人员应该知道什么?例如:什么时候使用一个而不是另一个,使用一个比另一个的优势等.

The Select and Where methods are available in Linq. What should every developer know about these two methods? For example: when to use one over the other, any advantages of using one over the other, etc.

推荐答案

Where

查找匹配的项目并仅返回匹配的项目(过滤).

finds items that match and only returns those that do (filtering).

-> IEnumerable输入,IEnumerable输出

选择

为源中的所有项返回某些内容(投影/转换).某些东西可能是项目本身,但更常见的是某种投影.

returns something for all items in the source (projection / transformation). That something might be the items themselves, but are more usually a projection of some sort.

-> IEnumerable输入,IEnumerable输出

这篇关于Linq:Select 和 Where 有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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