学习Lambda表达式最好的书是什么? [英] What's the best book to learn Lambda expressions?

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

问题描述

我正在学习MS MVC Core 2 for web,它使用如下代码:

I'm learning MS MVC Core 2 for web, and it uses code like this:

         ;       产品= repository.Products

                  &NBSP ; .Where(p => category == null || p.Category == category)

                     .OrderBy(P => p.ProductId)

               &NBSP ;    .Skip((productPage - 1)*每页)

               &NBSP ;    .Take(PageSize)

                Products = repository.Products
                    .Where(p => category == null || p.Category == category)
                    .OrderBy(p => p.ProductId)
                    .Skip((productPage - 1) * PageSize)
                    .Take(PageSize)

这被认为是Linq,还是Lambda表达式,或两者兼而有之,还是什么?什么是这样编码的好书?

Is this considered Linq, or Lambda expressions, or both, or what? What's a great book for coding like this?

感谢您的任何建议!

Corey

推荐答案

Lambdas是一个函数编程的东西。如果您对功能方面感兴趣,那么您需要使用F#等函数式语言阅读它们。它们的C#实现完全记录在

MSDN

Lambda是用于涉及=>的表达类型的术语。它通常用于LINQ,但可以在任何地方使用(例如表达式主体,赋值等)。 

Lambda is the term used for the type of expression involving the =>. It is commonly used in LINQ but can be used anywhere (e.g. expression bodies, assignment, etc). 

LINQ是允许查询任意数据的框架的名称。您的调用(例如Where,OrderBy等)恰好由LINQ库提供。最终它们只是扩展方法。

LINQ is the name for the framework that allows querying arbitrary data. Your calls (e.g. Where, OrderBy, etc) happen to be provided by the LINQ library. Ultimately they are just extension methods though.

LINQ语法是C#(和VB.NET)中使用的语法,在代码中使用类似SQL的结构而不是使用扩展方法
直接。您的代码未使用LINQ语法。这很好,但因为语法只是编译器糖。编译器将其转换为基础扩展方法。 LINQ语法可以根据您的需要与扩展方法结合使用。这是你的逻辑使用两者的
因为Skip和Take没有LINQ语法等价。 

LINQ syntax is the syntax used in C# (and VB.NET) to use SQL-like constructs in code rather than using the extension methods directly. Your code isn't using the LINQ syntax. That's fine though because the syntax is just compiler sugar. The compiler converts it to the underlying extension methods. LINQ syntax can be combined with the extension methods based upon your needs. Here's your logic using both because Skip and Take don't have LINQ syntax equivalence. 

//Using a combination of LINQ syntax, extension methods and lambdas
Products = (from p in repository.Products
            where category == null || p.Category == category
            orderby p.ProductId
            select p).Skip((productPage - 1) * PageSize).Take(PageSize);

           


这篇关于学习Lambda表达式最好的书是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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