We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 9 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
LINQPad是学习LINQ的好工具
LINQPad is a good tool for learning LINQ
Lambda 就是这样一种东西,一旦你开始思考,你就会“明白”它。 如果您当前正在使用委托,则可以将其替换为 lambda。 还有
System.Action<...>
、System.Func<...>
和System.Predicate<...>< /code> 添加是很好的快捷方式。 一些显示语法的示例会有所帮助(警告:它们很无聊,但我想说明如何交换函数):
最让我困惑的是快捷语法,例如当使用 System.Action 只执行不带参数的委托时你可以使用:
或者你可以这样做:
当你有一个带有一个参数的
Action
、Func
或Predicate
时,你可以省略括号:or:
代替:
or 走向极端:
如上所示,单行 lambda 不需要 return 语句,但多行
Func
lambda 需要。我认为您会发现学习如何使用 lambda 的最佳方法是大量使用集合,并将 System.Linq 包含在您的 using 命名空间中 - 您将看到大量针对集合的扩展方法,其中大多数方法都允许您锻炼您的 lambda 知识。
Lambdas are just something that, once you get your head around, you "get" it. If you're using a delegate currently, you can replace it with a lambda. Also the
System.Action<...>
,System.Func<...>
, andSystem.Predicate<...>
additions are nice shortcuts. Some examples showing syntax would be helpful though (warning: they are inane but I wanted to illustrate how you can swap functions):Mostly what confused me was the shortcut syntax, for example when using System.Action to just execute a delegate with no parameters you could use:
Or you could do:
When you've got an
Action
,Func
, orPredicate
that takes one argument you can omit the parenthesis:or:
instead of:
or to go to the extreme:
As shown above, single line lambdas do not require the return statement, though multiline
Func
lambdas do.I think you will find the best way to learn how to use lambdas is to work a lot with collections and include System.Linq in your using namespaces - you will see a ton of extension methods for your collections and most of these methods allow you to exercise your knowledge of lambdas.
目前我发现的最好的就是这个链接。 这是一个让我们练习的测验,但我想要更多的 Lambda,而不是 LINQ。
The best that I have found is this link for the moment. It's a quiz that let met practice, but I would like something more Lambda and less LINQ.