Linq和Lambda表达式 [英] Linq and lambda expression

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

问题描述

LINQ和Lambda表达式之间有什么区别?使用lambda代替linq查询有什么好处?

What is the difference between LINQ and Lambda Expressions? Are there any advantages to using lambda instead of linq queries?

推荐答案

Linq是语言集成查询.使用linq时,通常会使用一个小的匿名函数作为参数.那个小的匿名函数是lambda表达式.

Linq is language integrated query. When using linq, a small anonymous function is often used as a parameter. That small anonymous function is a lambda expression.

var q = someList.Where(a => a > 7);

在上面的查询中,a => a > 7是一个lambda表达式.等效于编写一个小的实用程序方法并将其传递给Where:

In the above query a => a > 7 is a lambda expression. It's the equivalent of writing a small utility method and passing that to Where:

bool smallMethod(int value)
{
  return value > 7;
}

// Inside another function:
var q = someList.Where(smallMethod);

这意味着您的问题确实无法回答. Linq和lambda是不可互换的,而lambda是实现linq的技术之一.

This means that your question is really not possible to answer. Linq and lambdas are not interchangeable, rather lambdas are one of the technologies used to implement linq.

这篇关于Linq和Lambda表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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