什么是设备以及如何使用lambda表达式? [英] What is appliance and how to use lambda expressions?

查看:75
本文介绍了什么是设备以及如何使用lambda表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到Lambda表达式是C#的强大功能,但我发现自己对它们感到迷惑.他们如何改善我的生活或改善我的代码?任何人都可以指出学习此类表达的良好资源吗?

I've read that Lambda Expressions are an incredibly powerful addition to C#, yet I find myself mystified by them. How can they improve my life or make my code better? Can anyone point to a good resource for learning such expressions?

它们看起来很酷,但是它们与我作为asp.net开发人员的日常生活有什么关系?

They seem cool as hell, but how do they relate to my day-to-day life as an asp.net developer?

感谢您提供的示例,也感谢您提供Eric White文章的链接.我现在还在消化那些.一个简单的问题:lambda表达式除查询外还对其他有用吗?我见过的每个示例都是一个查询构造.

Thanks for the examples, and thanks for the link to Eric White's articles. I'm still digesting those now. One quick question: are lambda expressions useful for anything other than querying? Every example I've seen has been a query construct.

推荐答案

:是lambda表达式,对查询以外的其他功能都是有用的

: are lambda expressions useful for anything other than querying

Lamba表达式不过是方便的内联"函数编写方式.

Lamba expressions are nothing much other than a convenient way of writing a function 'in-line'.

因此,它们在任何需要使用一些代码的地方都非常有用,这些代码可以像一个单独的函数一样被调用,但实际上是在调用者内部编写的. (除了将相关代码保存在文件中的同一位置之外,这还允许您使用可变范围来玩有趣的游戏-请参阅"closures"以获取参考.)

So they're useful any place you wanted a bit of code which can be called as though it's a separate function but which is actually written inside its caller. (In addition to keeping related code in the same location in a file, this also allows you to play fun games with variable scoping - see 'closures' for a reference.)

与查询无关的lamba用法的示例可能是一些代码,这些代码以ThreadPool.QueueUserWorkItem开始以异步方式进行操作.重要的一点是,您还可以使用匿名委托(这是C#2的介绍)或仅使用一个单独的类成员函数来编写此代码.

An example of a non-query-related use of a lamba might be a bit of code which does something asynchronously that you start with ThreadPool.QueueUserWorkItem. The important point is that you could also write this using anonymous delegates (which were a C#2 introduction), or just a plain separate class member function.

http://blogs.msdn.com/jomo_fisher /archive/2005/09/13/464884.aspx 是对所有这些东西的精妙分步介绍,可能会对您有所帮助.

This http://blogs.msdn.com/jomo_fisher/archive/2005/09/13/464884.aspx is a superb step-by-step introduction into all this stuff, which might help you.

这篇关于什么是设备以及如何使用lambda表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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