In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you the "C # Lambda expression how to use", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "C # Lambda expression how to use" this article.
C # language is still quite common, here we mainly introduce C # Lambda expressions, including the introduction of a Lambda is a delegate, a delegate points to a method and so on.
Have you ever come into contact with C # Lambda expressions? do you think anonymous methods are good, reducing a lot of code, but the use of anonymous methods is not humanized? what is humanization? For example, you can read the program code in a natural language, which is humanized. There are some new methods in List under the System.Collections.Generic namespace in. Net 2.0. For example, Find, how do we call it if we use anonymous methods:
Books.Find (delegate (Book book) {return book.Price)
< 50;}); 代码是很简单,但是却无法朗读出来,来看看C# Lambda表达式的写法: books.Find(book=>Book.Price xbracket 1 deleage (int x) {return xanti1;} / / is followed by statement block x = > {return xanti1;} delegate (int x) {return xanti1;} / / input parameters can also be typed, and don't forget parentheses oh (int x) = > delegate (int x) {return xbrac1;} / / you can also have multiple input parameters separated by commas, and don't forget parentheses (xpareny) = > xpareny delegate (int xint int y) {return xbractey. } / / No parameter is OK () = > 1 delegate () {return 1;}
That's the way she uses C # Lambda expressions, but there are a lot of stories and tricks behind Lambda. You can build an expression tree with C # Lambda expressions, and the expression tree is as important to Linq as the root is to the tree. We will not discuss the problem of expression tree here, and this thing cannot be clearly explained in a few words. We will discuss it further when the time is ripe.
Read more about C # Lambda expressions
Lambda actually has a long history. The machines we use now belong to the von-Neumann system and belong to Turing machines. Before that, there was a theory called λ calculus, but Turing machines became popular because they were implemented first. λ calculus later led to functional programming languages, especially Lisp. In functional programming languages, functions are elements such as *. The parameters and return values of functions are all functions. The program has no variables, and functions are nested functions. And functional programming languages have always existed in ivory towers, so they are not commonly used in industry, but in recent years, industry likes the "retro" style, so functional programming languages have slowly stepped onto the stage of history. Functional programming can solve some problems that imperative programming is difficult to solve (or very troublesome to solve). What if C # wants to do function style programming? It is certainly not feasible to rely on the original method definition. The anonymous method of 2.0 solves this problem in some way, but it is still not enough. Lambda in 3.0 has finally solved very well, a Lambda is a delegate, a delegate points to a method, and now we can simply pass the method as a parameter using Lambda, and it can also be nested layer upon layer, which is very simple.
The above is all the content of the article "how to use C # Lambda expressions". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.