In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you what the syntax of LINQ query is, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Lambda expression
Var list = new [] {"aa", "bb", "ac"}; var result = Array.FindAll (list, s = > (s.IndexOf ("a") >-1)); foreach (var v in result) Console.WriteLine (v)
In fact, it is similar to the anonymous methods in 2.0, which are used to generate inline methods, except that the syntax of Lambda expressions is more concise. The syntax is as follows:
(parameter list) = > expression or statement block
Where:
Number of parameters: can have multiple parameters, one parameter, or no parameters.
Expression or statement block: this part is the implementation part of the function that we usually write (function body).
Here is a complex example combined with the extension method:
Public delegate int mydg (int a, int b); public static class LambdaTest {public static int oper (this int a, int b, mydg dg) {return dg (a, b);}} Console.WriteLine (1.oper (2, (a, b) = > a + b)); Console.WriteLine (2.oper (1, (a, b) = > a-b))
LINQ query syntax
Var persons = new List {new Person {username = "a", age=19}, new Person {username = "b", age=20}, new Person {username = "a", age=21},}; var selectperson = from p in persons where p.age > = 20 select p.username.ToUpper (); foreach (var p in selectperson) Console.WriteLine (p)
LINQ query syntax is a convenient declarative simplification when using standard LINQ query operators to express queries. This syntax can improve readability and simplicity when expressing queries in code, and it is easy to read and write correctly. Visual Studio provides complete intelligent sensing and compile-time checking support for query syntax. At the bottom, the compiler translates the expression of the query syntax into explicit method call code, which is implemented by new extension methods and Lambda expression language features. The above query syntax is equivalent to the following code:
Var selectperson = persons.Where (p = > p.age > = 20) .Select (p = > p.username.ToUpper ())
LINQ query syntax can achieve more than 90% of the function of T-SQL (because T-SQL is based on two-dimensional tables, LINQ query syntax is simpler and more flexible than T-SQL), but due to intelligent sensing, select cannot be entered at the beginning.
The above is all the content of the article "what is the syntax of LINQ query?" 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