C#3.0和lambdas [英] C#3.0 and lambdas

查看:85
本文介绍了C#3.0和lambdas的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Slashdot上有一个关于未来C#3.0的讨论:
http://developers.slashdot.org/devel...?tid=109&tid=8

http://msdn.microsoft.com/vcsharp/future/


有许多不同之处,但它看起来更像Python:
http://download.microsoft.com/downlo...cification.doc


我非常喜欢lambda sintax。如果只有一个参数,则可以省略

括号。如果没有
参数,则需要它们。声明正文允许lambda做任何事情。


x => x + 1表达主体

x => {return x + 1;声明正文

(x,y)=> x * y多个参数

()=> Console.WriteLine()没有参数


语法看起来不错,但对于python,Statement body语法可以

成为一个问题。


再见,

熊宝宝

On Slashdot there is a discussion about the future C#3.0:
http://developers.slashdot.org/devel...?tid=109&tid=8

http://msdn.microsoft.com/vcsharp/future/

There are many differences, but it looks a bit more like Python:
http://download.microsoft.com/downlo...cification.doc

I like the lambda sintax enough. If there is a single parameter the
parentheses may be omitted. They are required if there aren''t
parameters. The statement body allows the lambda to do anything.

x => x + 1 Expression body
x => { return x + 1; } Statement body
(x, y) => x * y Multiple parameters
() => Console.WriteLine() No parameters

The syntax seems nice, but for python the "Statement body" syntax can
be a problem.

Bye,
bearophile

推荐答案

是*********** *@lycos.com 写道:
be************@lycos.com wrote:
在Slashdot上有一个关于未来C#3.0的讨论:
http://developers.slashdot.org/devel ... ?tid = 109& tid = 8
http://msdn.microsoft.com/vcsharp/future/

"扩展程序可构建组合API,

具有相同的表达能力在诸如关系数据库和XML之类的域中查询语言。

有许多不同之处,但它看起来更像Python:
http://download.microsoft.com/downlo...cification.doc
On Slashdot there is a discussion about the future C#3.0:
http://developers.slashdot.org/devel...?tid=109&tid=8

http://msdn.microsoft.com/vcsharp/future/
"The extensions enable construction of compositional APIs that
have equal expressive power of query languages in domains such
as relational databases and XML."
There are many differences, but it looks a bit more like Python:
http://download.microsoft.com/downlo...cification.doc




同时,在python-dev土地上:


是否有人真正依附于嵌套元组函数参数; ''def

fxn((a,b)):打印a,b''? /.../


如果他们离开,有人真的会非常适合吗?我愿意写一个PEP,以便在2.6中删除它们,如果

人为它而弃用它。


< / F>



meanwhile, over in python-dev land:

"Is anyone truly attached to nested tuple function parameters; ''def
fxn((a,b)): print a,b''? /.../

Would anyone really throw a huge fit if they went away? I am willing
to write a PEP for their removal in 2.6 with a deprecation in 2.5 if
people are up for it."

</F>


您好,
"是否有人真正依附于嵌套元组函数参数; ''def
fxn((a,b)):打印a,b''? /.../

如果他们离开,有人真的会非常适合吗?我愿意写一个PEP,以便在2.6中删除它们,如果有人愿意,可以弃用2.5。
"Is anyone truly attached to nested tuple function parameters; ''def
fxn((a,b)): print a,b''? /.../

Would anyone really throw a huge fit if they went away? I am willing
to write a PEP for their removal in 2.6 with a deprecation in 2.5 if
people are up for it."




首先我错过了def,并且想哦,不要删除它

有时候我会将一个元组传递给我的函数。

但是我看到了 DEF"关键字和实现我从来没有使用过这样的函数语法。


因此,在一行(我的邮件程序截断它):

def fxn((a,b)):打印a,b''


要删除,而不是:


''fxn((a,b)''函数调用

我可以删除。

bye by Wolfgang



First I missed the def and thought "Oh no don''t remove it
sometimes I pass a tuple to my functions".
But the I saw the "def" keyword and realized I never
used such a function syntax.

So, in one line (my mailer truncated it):

def fxn((a,b)): print a,b''

for removal, not:

''fxn((a,b)'' function calls
I''m ok with removal.
bye by Wolfgang


Fredrik Lundh schreef:
Fredrik Lundh schreef:
同时,在python-dev土地上:

是否有人真正依附于嵌套元组函数参数;''def
fxn((a,b)):打印a,b''?/.../

如果他们离开,有人真的会非常适合吗?我愿意
写一个PEP,在2.6中删除,如果有人愿意,可以弃用2.5。
meanwhile, over in python-dev land:

"Is anyone truly attached to nested tuple function parameters; ''def
fxn((a,b)): print a,b''? /.../

Would anyone really throw a huge fit if they went away? I am willing
to write a PEP for their removal in 2.6 with a deprecation in 2.5 if
people are up for it."




我不喜欢看到它消失了。我喜欢能够写b
,例如:


def drawline((x1,y1),(x2,y2)) :

#d原始从x1,y1到x2,y2的行

foo(x1,y1)

bar(x2,y2)


而不是


def drawline(p1,p2):

x1,y1 = p1

x2,y2 = p2

#从x1,y1到x2画一条线,y2

foo(x1,y1)

bar(x2,y2)





def drawline(p1,p2):

#从p1 [0]画一条线,p1 [ 1]到p2 [0],p2 [1]

foo(p1 [0],p1 [1])

bar(p2 [0],p2 [1 ])

-

如果我能够进一步看到,那只是因为我站在了巨人的肩膀上。 - Isaac Newton


Roel Schroeven



I for one would not like to see that disappear. I like being able to
write, for example:

def drawline((x1, y1), (x2, y2)):
# draw a line from x1, y1 to x2, y2
foo(x1, y1)
bar(x2, y2)

instead of

def drawline(p1, p2):
x1, y1 = p1
x2, y2 = p2
# draw a line from x1, y1 to x2, y2
foo(x1, y1)
bar(x2, y2)

or

def drawline(p1, p2):
# draw a line from p1[0], p1[1] to p2[0], p2[1]
foo(p1[0], p1[1])
bar(p2[0], p2[1])
--
If I have been able to see further, it was only because I stood
on the shoulders of giants. -- Isaac Newton

Roel Schroeven


这篇关于C#3.0和lambdas的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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