我失去了一些有关LINQ? [英] Am I missing something about LINQ?

查看:143
本文介绍了我失去了一些有关LINQ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎失去了一些东西约LINQ。对我来说,它看起来像它采取了一些,我最不喜欢的和SQL的要素移动它们到C#语言和使用他们的其他东西。

I seem to be missing something about LINQ. To me, it looks like it's taking some of the elements of SQL that I like the least and moving them into the C# language and using them for other things.

我的意思,我可以看到使用比数据库的其他东西类似SQL语句的好处。但是如果我想要写SQL,那么,为什么不写SQL,并保持它跳出C#?缺少什么我在这里?

I mean, I could see the benefit of using SQL-like statements on things other than databases. But if I wanted to write SQL, well, why not just write SQL and keep it out of C#? What am I missing here?

推荐答案

LINQ是不是SQL。 LINQ是关于正对对象应用功能的编程paradigmns。

LINQ is not about SQL. LINQ is about being apply functional programming paradigmns on objects.

LINQ to SQL的是内置的ontop LINQ基础的ORM,但LINQ得多。我不使用LINQ到SQL,但我使用LINQ所有的时间

LINQ to SQL is an ORM built ontop of the LINQ foundation, but LINQ is much more. I don't use LINQ to SQL, yet I use LINQ all the time.

以找出两个列表的交集的任务:

Take the task of finding the intersection of two lists:

LINQ之前,这个任务需要编写,遍历该小单子一次在大名单O(N * M)的每个项目一个嵌套的foreach,大约需要10行代码。

Before LINQ, this tasks requires writing a nested foreach that iterates the small list once for every item in the big list O(N*M), and takes about 10 lines of code.

foreach (int number in list1)
{
    foreach (int number2 in list2)
    {
        if (number2 == number)
        {
            returnList.add(number2);
        }
    }
}



使用LINQ,但它的在一行代码同样的事情:

Using LINQ, it does the same thing in one line of code:

var results = list1.Intersect(list2);

您会发现,看起来不像LINQ,但它是。你并不需要使用表达式语法,如果你不想。

You'll notice that doesn't look like LINQ, yet it is. You don't need to use the expression syntax if you don't want to.

这篇关于我失去了一些有关LINQ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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