Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the LINQ expression?

Shulou Source: shulou.com Published: 2022-06-02 09:03:03 09月18日 Update

This article mainly explains "what is a LINQ expression". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is a LINQ expression".

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 ())

LINQ expression parsing:

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)

Query operator and extension method parsing:

Query operators are another important facility in LINQ expressions, 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, Funcbool > predicate) {foreach (T item in source) if (predicate (item)) yield return item } Thank you for your reading, the above is the content of "what is a LINQ expression". After the study of this article, I believe you have a deeper understanding of what the LINQ expression is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Expressions queries operators methods data learning information content databases schemes languages problems integration important information sources typical benefits objects that is ideas Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology OPPO Reno vpn Xiaomi Redmi