LINQ

xiaoxiao2021-04-04  255

The PDC 05 exposes C # 3.0 and linq project, what is Linq? Simply said that Linq is a language level

Query syntax library, she can query the variables in the language in a class SQL syntax, such as arrays,

COLLECTIONS. In case:

Static void ObjectQuery ()

{

Var people = new list

()

{

NEW PERSON {age = 12, name = "bob"},

NEW PERSON {AGE = 18, Name = "cindy"},

NEW PERSON {AGE = 13}

}

Var teenagers = from p in people where p.age> 12 && P.age <20 SELECT P;

Console.writeline ("Result:");

Foreach (Var in Teenagers)

{

Console.Writeline ("> name = {0}, agn = {1}", val.name, val.age);

}

Console.readline ();

Class Person

{

Public int Age;

Public String Name;

}

Person is a category, which has established a Person's Collection with Generic List in the ObjectQuery.

The VAR type here is a new type of C # 3.0, from the language, this type can be designated as any type,

Just like a variant, from the Complier perspective, it is a lazy-determine type, compiled by Complier

During the period to determine the real type, the next strange syntax is LINQ.

Var teenagers = from p in people where p.age> 12 && P.age <20 SELECT P;

Do you feel very similar to SQL? This section is the meaning of the AGE, which is more than 12, which is selected from the person.

In addition to this simple query, Linq also supports Join, Distinct and other syntax.

Basically Linq is just a group of library, c # 3.0 and vb.net 9.0 Complier use this library to implement

The above new grammar, all special syntax will be compiled into a program that uses Linq Library.

LINQ is working in the formula language.

转载请注明原文地址:https://www.9cbs.com/read-131885.html

New Post(0)