LINQ vs Lambda vs匿名方法vs代表 [英] LINQ vs Lambda vs Anonymous Methods vs Delegates

查看:161
本文介绍了LINQ vs Lambda vs匿名方法vs代表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 任何人都可以解释什么是LINQ,Lambda,匿名方法,代表意味着什么?

  1. Can anyone explain what are the LINQ, Lambda, Anonymous Methods, Delegates meant?

这3个如何相互不同?

How these 3 are different for each other?

是否可替换另一个?

当Google Googling

I didn't get any concrete answer when i did Googling

推荐答案

LINQ是一个广泛的技术名称,涵盖了大量的.NET 3.5和C#3.0更改; 查询语言和吨更多。

LINQ is a broad technology name covering a large chunk of .NET 3.5 and the C# 3.0 changes; "query in the language" and tons more.

代理可以与功能指针相媲美;一个方法句柄作为一个对象,如果你喜欢,即

A delegate is comparable to a function-pointer; a "method handle" as an object, if you like, i.e.

Func<int,int,int> add = (a,b) => a+b;

是一种写一个委托的方式,然后我可以打电话。代表也支持事件和其他回调方式。

is a way of writing a delegate that I can then call. Delegates also underpin eventing and other callback approaches.

匿名方法是创建委托实例的2.0简短方法,例如:

Anonymous methods are the 2.0 short-hand for creating delegate instances, for example:

someObj.SomeEvent += delegate {
    DoSomething();
};

他们还通过捕获的变量(未显示在上面)中引入了完整的关闭语言。 C#3.0引入了lambdas,其中可以产生与匿名方法相同的方法:

they also introduced full closures into the language via "captured variables" (not shown above). C# 3.0 introduces lambdas, which can produce the same as anonymous methods:

someObj.SomeEvent += (s,a) => DoSomething();

但可以将编译为表达式树,以完整LINQ对(例如)数据库。例如,您不能运行针对SQL Server的代理!但是:

but which can also be compiled into expression trees for full LINQ against (for example) a database. You can't run a delegate against SQL Server, for example! but:

IQueryable<MyData> source = ...
var filtered = source.Where(row => row.Name == "fred");

可以将转换成SQL,因为它被编译成表达式树( System.Linq.Expression )。

can be translated into SQL, as it is compiled into an expression tree (System.Linq.Expression).

所以:


  • 可以使用匿名方法创建一个委托

  • 一个lambda可能与anon-method相同,但不一定

  • an anonymous method can be used to create a delegate
  • a lambda might be the same as an anon-method, but not necessarily

这篇关于LINQ vs Lambda vs匿名方法vs代表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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