Linq vs Loop哪个最好 [英] Linq vs Loop Which is best

查看:102
本文介绍了Linq vs Loop哪个最好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个项目列表。我可以使用Linq查询或for循环来获取我需要的数据。但我想知道哪个最好?



我认为Linq的工作方式与创建循环并解析值并提取查询中提供的数据相同。如果我错了,请纠正我..

解决方案

LINQ。它实际上取决于LINQ到底是什么。例如,如果这是 LINQ to SQL ,那么关于循环的猜测根本就不正确。显然,LINQ被转换为SQL查询,它被传递到服务器部分,该部分针对处理查询进行了优化,因此性能差异可能非常惊人。



-SA

Hi,
I have a list of Items. I can either use a Linq query or for loop to get the data that is needed by me. But I wanted to know which is Best ?

I think Linq works as same way of creating a loop and parsing the values and extract the data that is given in the query. Correct me if I am wrong..

解决方案

LINQ. It actually depends on LINQ to what. If this is, for example, LINQ to SQL, your speculations about loop are not correct at all. Apparently, LINQ is translated to SQL query, which is passed to the server part, which is optimized for processing queries, so performance difference could be striking.

—SA


这篇关于Linq vs Loop哪个最好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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