C# basic learning--LINQ (2

Table of contents

standard query operators

 Signatures of standard query operators

 Query Expressions and Standard Query Operators

takes the delegate as a parameter

 LINQ predefined delegate types

Example using delegate parameters

Example using Lambda expression parameters

 LINQ to XML

markup language

 XML basics

 XML class

1. Create, save, load and display XML documents 

Create an XML tree

 Use the value of the XML tree

Add nodes and manipulate XML

 Using XML features

Other types of nodes

XComment  XDeclaration  XProcessingInstruction

 LINQ Queries using LINQ to XML


standard query operators

Standard query operators consist of a series of API methods

Sequence refers to the class that implements the Ienumerable<> interface, including List<>, Dictionary<>, Stack<>, Array, etc.

 Signatures of standard query operators

An extension method is a public static method. Although it is defined in a class, its purpose is to add functionality to another class (the first parameter), which must be preceded by the keyword this

 Query Expressions and Standard Query Operators

Each query expression can also be written using method syntax with standard query operators. The compiler translates each query expression into the form of the standard query operators

takes the delegate as a parameter

Many operators accept generic delegates as parameters.

Generic delegates are used to provide user-defined code to operators

 LINQ predefined delegate types

 The return type parameter has an out keyword, which means that it can be covariant, that is, it can accept the declared type or a type derived from this type. The input parameter has a keyword in, which means that it can be inverted, that is, it can accept the declared type or the type derived from this class

Looking at the statement of Count, the second parameter must be a delegate object, which accepts a single parameter of type T as a method parameter and returns a value of type bool. This form of delegation is called a predicate

Example using delegate parameters

 Output: 4

Example using Lambda expression parameters

If the function used to initialize the delegate does not need to be called elsewhere, or the code statement in the function body is equal to a

Then using lambda expression is a good choice

 Anonymous method:

 LINQ to XML

Extensible Markup Language (XML) is an important method of storing and exchanging data

markup language

A markup language is a set of tags in a document that provide information about the document and organize its content. That is, markup tags are not data about the document -- they contain data about the data. Data about data is called metadata

 XML basics

The data in an XML document consists of an XML tree, which mainly consists of nested elements

Elements are the basic elements of an XML tree. Each element has a name and contains data, and some elements can contain other nested elements. Elements are delimited by opening and closing tags. Any element containing data is between the opening and closing tags

 XML class

I haven't touched this part, so I can only take screenshots of it all.

1. Create, save, load and display XML documents 

Create an XML tree

 Use the value of the XML tree

Add nodes and manipulate XML

 Using XML features

Other types of nodes

XComment  XDeclaration  XProcessingInstruction

 LINQ Queries using LINQ to XML

 

Guess you like

Origin blog.csdn.net/zaizai1007/article/details/130275022