Linq“进入”和“让”相等??? [英] Linq "into" and "let" equally???

查看:83
本文介绍了Linq“进入”和“让”相等???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Linq进入和让同样???

http://www.alvas.net - C#和VB.Net开发人员的音频工具

Linq "into" and "let" equally???

http://www.alvas.net - Audio tools for C# and VB.Net developers

推荐答案

11月23日上午8:22,Alexander Vasilevsky < al ... @ alvas.netwrote:
On Nov 23, 8:22 am, "Alexander Vasilevsky" <al...@alvas.netwrote:

Linq" into"和让相等???
Linq "into" and "let" equally???



你的意思是他们做同样的事情吗??如果是这样,你的意思是

select ... into而不是分组......进入?


我会假设你的意思是选择...进入。它们并不完全相同。

当你选择选择......进入时你有一个*单*范围变量

那个点;任何先前的范围变量基本上都没有了。


如果你做让然后它只是引入一个* new *范围变量。所以,

例如,你可以这样做:


var query =来自Enumerable.Range(0,10)中的x

让y = x * 2

选择x + y;


但如果你这样做:


var query = from x in Enumerable.Range(0,10)

选择x * 2进入y

选择x + y;


它会失败,因为在x + y处阶段x已经不再可用。


(我还没有尝试过上面的代码 - 当我有
时我就要这么做了将3.5安装到我的笔记本电脑上。)


Jon

Do you mean "do they do the same thing"? If so, do you mean
"select ... into" rather than "group ... into"?

I''ll assume you mean "select ... into". They''re not quite the same.
When you do "select ... into" you have a *single* range variable at
that point; any previous range variables are gone, basically.

If you do "let" then it just introduces a *new* range variable. So,
for instance, you could do:

var query = from x in Enumerable.Range(0, 10)
let y = x*2
select x+y;

But if you do:

var query = from x in Enumerable.Range(0, 10)
select x*2 into y
select x+y;

it will fail, because at the "x+y" stage "x" is no longer available.

(I haven''t tried the above code yet - I''m about to do so when I''ve
installed 3.5 onto my laptop.)

Jon


对不起,什么?
Sorry, what?

Jon Skeet [C#MVP]写道:
Jon Skeet [C# MVP] wrote:

11月23日上午8:22,Alexander Vasilevsky < al ... @ alvas.netwrote:
On Nov 23, 8:22 am, "Alexander Vasilevsky" <al...@alvas.netwrote:

Linq" into"和让相等???
Linq "into" and "let" equally???



你的意思是他们做同样的事情吗??如果是这样,你的意思是

select ... into而不是分组......进入?


我会假设你的意思是选择...进入。它们并不完全相同。

当你选择选择......进入时你有一个范围变量在

那个点;任何先前的范围变量基本上都没有了。


如果你做让然后它只是引入了一个新的范围变量。所以,

例如,你可以这样做:


var query =来自Enumerable.Range(0,10)中的x

让y = x * 2

选择x + y;


但如果你这样做:


var query = from x in Enumerable.Range(0,10)

选择x * 2进入y

选择x + y;


Do you mean "do they do the same thing"? If so, do you mean
"select ... into" rather than "group ... into"?

I''ll assume you mean "select ... into". They''re not quite the same.
When you do "select ... into" you have a single range variable at
that point; any previous range variables are gone, basically.

If you do "let" then it just introduces a new range variable. So,
for instance, you could do:

var query = from x in Enumerable.Range(0, 10)
let y = x*2
select x+y;

But if you do:

var query = from x in Enumerable.Range(0, 10)
select x*2 into y
select x+y;



通过这样的查询,我总是想知道为什么有人想要

以这种方式使用该结构...


我的意思是:为什么有人会使用select< expressioninto< var?或者我是
唯一一个在设置导向的功能和linq中的命令式编程之间找到痛苦组合的人有点'奇怪'?


FB


-

--------------------- -------------------------------------------------- -

LLBLGen Pro的首席开发人员,.NET的高效O / R映射器

LLBLGen Pro网站: http://www.llblgen.com

我的.NET博客: http://weblogs.asp.net/fbouma

Microsoft MVP(C#)

------------------------------------------------ ------------------------

With queries like that, I always wonder why on earth would anyone want
to use that construct in that way...

I mean: why would anyone use select <expressioninto <var? Or am I
the only one who finds the painful mix between set oriented
functionality and imperative programming within linq a bit ''odd'' ?

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------


这篇关于Linq“进入”和“让”相等???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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