In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to write LINQ expressions, 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 learn about it!
Introduction to LINQ expression
Beyond 1.OO (object oriented): access and integration of information. Relational database and XML are typical applications.
2.NET Language Integrated Query (LINQ): instead of using proprietary solutions specific to relational databases or XML, general solutions are used to solve the problems of access and integration of various information sources.
3. In LINQ, query has become a part of programming language, which makes query expressions get the benefits of strongly typed languages such as compile-time syntax checking, rich metadata, intelligence awareness and so on.
Knowing LINQ expression for the first time
Class app {static void Main () {string [] names = {"Burke", "Connor", "Frank", "Everett", "Albert", "George", "Harris", "David"}; IEnumerable query = from s in names where s.Length = = 5 orderby s select s.ToUpper (); foreach (string item in query) Console.WriteLine (item);}}
Parsing of LINQ expression
IEnumerable query = from s in names where s.Length = = 5 orderby s select s.ToUpper ()
Semantically equivalent to the following "method-style (method-based) query":
IEnumerable query = names .Where (s = > s.Length = = 5) .OrderBy (s = > s) .Select (s = > s.ToUpper ())
Parsing of LINQ query expression
Func filter = delegate (string s) {return s.Length = = 5;}; Func extract = delegate (string s) {return s;}; Func project = delegate (string s) {return s.ToUpper ();}; IEnumerable query = names.Where (filter) .OrderBy (extract) .Select (project)
Analysis of query operator and extension method
Query operators are another important facility in LINQ, and LINQ uses extension methods to define query operators, such as the where operator:
Namespace System.Linq {public static class Enumerable {public static IEnumerable Where (this IEnumerable source, Func predicate) {foreach (T item in source) if (predicate (item)) yield return item;} above is all the content of this article "how to write LINQ 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.