什么是LINQ和Lambda前pression在.NET中的效率和性能? [英] What is the Efficiency and Performance of LINQ and Lambda Expression in .Net?

查看:441
本文介绍了什么是LINQ和Lambda前pression在.NET中的效率和性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用的.Net 3.5和VS 2008多一个月。最喜欢的.NET开发人员,我从在.net 1.0安培多年的经验发展而来; 2.0和VS 2005年就在最近,我发现了LINQ和Lambda前pressions的简单性和力量,在我最近的问题,如的通过LINQ 查找列表中的项目,<一个href="http://stackoverflow.com/questions/1176038/convert-or-map-a-class-instance-to-a-list-of-another-one-by-using-lambda-or-linq">Convert或地图类实例的另一个列表使用LAMBDA或LINQ 和<一href="http://stackoverflow.com/questions/1178891/convert-or-map-a-list-of-class-to-another-list-of-class-by-using-lambda-or-linq">Convert或地图班上课的另一个列表清单通过使用lambda或LINQ 。

I have used .Net 3.5 and VS 2008 for more than a month. Like most .Net developers, I have evolved from years experience in .Net 1.0 & 2.0 and VS 2005. Just recently, I discovered the simplicity and power of LINQ and Lambda Expressions, as in my recent questions such as Find an item in list by LINQ, Convert or map a class instance to a list of another one by using Lambda or LINQ, and Convert or map a list of class to another list of class by using Lambda or LINQ.

我承认的Lambda和LINQ是更简单,易于阅读和他们似乎非常强大。在幕后,净编译器必须生成大量的code来实现这些功能。因此,我有点犹豫,切换到新的语法,因为我已经知道了旧的方式来达到同样的效果。

I admit that Lambda and LINQ are much simpler and easy to read and they seem very powerful. Behind the scenes, the .Net compiler must generate lots of code to achieve those functions. Therefore I am little bit hesitant to switch to the new syntax since I already know the "old" way to achieve the same results.

我的问题是有关的Lambda和LINQ的效率和性能。也许LAMBDA EX pressions大多是在​​线功能,在这种情况下,我想LAMBDA应该没问题。如何LINQ?

My question is the about the efficiency and performance of Lambda and LINQ. Maybe Lambda expressions are mostly in-line functions, in that case I guess Lambda should be okay. How about LINQ?

让我们只讨论LINQ到对象LINQ到SQL(LINQ到SQL)。任何意见,比较和经验?

Let's limit the discussion to LINQ-to-Objects LINQ-to-SQL (LINQ-to-SQL). Any comments, comparison and experiences?

推荐答案

有没有一个单一的答案就足够了这里。

There's no one single answer that will suffice here.

LINQ有多种用途,而且许多实现,因此许多影响到您的code效率。

LINQ has many uses, and many implementations, and thus many implications to the efficiency of your code.

如同每个科技作品在我们的指尖,LINQ能够而且将会被滥用和误用的一致好评,并区分能力,以及正确使用,只依赖于一件事:知识

As with every piece of technology at our fingertips, LINQ can and will be abused and misused alike, and the ability to distinguish between that, and proper usage, is only dependent on one thing: knowledge.

所以,我可以给你最好的建议就是去阅读关于如何LINQ的真正实施。

So the best advice I can give you is to go and read up on how LINQ is really implemented.

事情你应该检查到的:

  • LINQ以及如何使用现有的集合类型的方法和扩展方法
    • LINQ and how it uses the methods and extension methods on existing collection types
      • How LINQ Works
      • How LINQ works internally (Stack Overflow)
      • How does coding with LINQ work? What happens behind the scenes?
      • <一个href="http://stackoverflow.com/questions/796246/what-is-the-difference-between-linq-query-ex$p$pssions-and-extension-methods">What是LINQ查询EX pressions和扩展方法(堆栈溢出)
      • 的区别
      • What is the difference between LINQ query expressions and extension methods (Stack Overflow)

      和往常一样,在看效率问题,唯一安全的方法就是测量。创建使用LINQ,做一个单一的,知道了,事情一件code,并创建一个选择,然后同时测量,并努力改善。猜测和假设只会导致坏的结果。

      And as always, when looking at efficiency questions, the only safe approach is just to measure. Create a piece of code using LINQ that does a single, know, thing, and create an alternative, then measure both, and try to improve. Guessing and assuming will only lead to bad results.

      这篇关于什么是LINQ和Lambda前pression在.NET中的效率和性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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