Lambda和LINQ之间的区别? [英] Difference between lambda and LINQ?

查看:1148
本文介绍了Lambda和LINQ之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释一下lambda和linq之间的区别吗?

Can someone explain me the difference between lambda and linq?

请不要向我指出其他stackexchange答案或琐碎的解释,我已经检查了其中的大多数内容,并且它们令人困惑.

Please don't point me out to other stackexchange answers or trivial explanations, I've checked most of them and they're orribly confusing.

这些天,我已经使用了一些LINQ(我相信吗?)之类的表达式(仅仅是一个示例)

I've used a bit of LINQ (I believe?) in these days with expressions like (merely an invented example)

var result = object.Where(e => e.objectParameter > 5).Any()

哪个,应该在结果中返回一个布尔值,该布尔值表明是否有任何> 5的元素.

Which, should return in result a boolean which says if there is any element >5.

那么,LINQ和lambda是什么?

Ok, then, what are LINQ and lambda?

LINQ只是一个由C#团队开发并包含在内的库,一组功能

Is LINQ just a library, a set of functions, developed by C# team to include with

using System.Linq;

这为您提供了强大的"for循环"功能,其中有许多方法可以避免手脏"? (首先,FirstOrDefault,任何...等)

which gives you a powered "for loop" with many methods to avoid you getting your hands "dirty"? (First, FirstOrDefault, Any.... etc)

什么是Lambda?与上面相同吗?这是一种语言本身吗?它和LINQ有什么区别?我如何识别一个或另一个?

And what is Lambda? Is the same as above? It's a language on it's own? What is it and how it differs from LINQ? How do I recognize one or another?

谢谢

推荐答案

语言集成查询(LINQ)是在以下语言中引入的一组功能 Visual Studio 2008将强大的查询功能扩展到了 C#和Visual Basic的语言语法

Language-Integrated Query (LINQ) is a set of features introduced in Visual Studio 2008 that extends powerful query capabilities to the language syntax of C# and Visual Basic

lambda表达式是一个匿名函数,可用于 创建委托或表达式树类型.通过使用lambda 表达式,您可以编写可以通过以下方式传递的局部函数 参数或作为函数调用的值返回.

A lambda expression is an anonymous function that you can use to create delegates or expression tree types. By using lambda expressions, you can write local functions that can be passed as arguments or returned as the value of function calls.

Linq 使用 Lambda表达式来执行其某些功能.

Linq uses Lambda expression in order to execute some of its functionalities.

示例:

new [] { "Dan", "Yossi", "Ben" }.Where(item => item.Length == 3);

Lambda表达式:item => item.Length == 3
Linq:(from item in (new [] { "Dan", "Yossi", "Ben" }) where item.Length == 3)

Lambda expression: item => item.Length == 3
Linq: (from item in (new [] { "Dan", "Yossi", "Ben" }) where item.Length == 3)

这篇关于Lambda和LINQ之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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