LINQ (language-integrated query, language-integrated queries).
LINQ to Objects, LINQ-to-SQL, LINQ to DataSet, and LINQ to XML, which query and process object data (such as collections), relational data (such as SQL Server databases, and so on), DataSet object data, and XML structure data, respectively. operates primarily on data
-----------------------------------------------------
LINQ Syntax Basics--c#3.0
-------------------------------------------
Create an implicit local variable using var
Int number=; string [] strs=newstring [5]; UserInfo ui=New UserInfo ();
var number=; var strs=Newstring[]{"," "", "",""} "}; var ui=New UserInfo ();
The VAR keyword instructs the compiler to infer the type of the variable based on the initialization expression of the variable, which is the type of the variable that is hidden when the variable is declared with the VAR keyword. The var keyword can be used in the following four scenarios.
1. declaring local variables;
in 2.For statements;
in 3.Foreach statements;
in 4.Using statements;
Object initializer
Allows a developer to create a new object declaratively and set the values of each property of the object without invoking the class's constructor.
UserInfo UI =NewUserInfo {Username="Zhang San", Useraddr="Wuhan", Userage=" at", Usersex="male", Usertel="027-50459016"There are properties in//userinfo that can be set directly };
Collection initializer
The initializer is used to initialize a collection that consists of a series of elements enclosed in the tags "{" and "}".
list<intnew list<int012345 6789 }; You can initialize a collection inside {}
Creating an anonymous type Object
You can create a new object using the new operator and the anonymous object initializer.
// creating an Object of an anonymous type var New 1 " Zhang San " " male " " Wuhan " };
Creating a Stealth Array
A stealth array is similar to an anonymous type object. The invisible array is created using the var keyword and the array initializer, and the data type of the elements in the arrays initializer must be implicitly convertible to the same data type (cannot be null) element
var numbers = new [] {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , }; var STRs = new [] { " he " , she " , it " };
Lambda expression: A lambda expression can be used with a delegate's seat
A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create a delegate or an expression tree type. A lambda expression consists of an input parameter, a lambda operator (= =), and an expression (or block of statements). The basic form of a lambda expression is as follows:
(input parameters) = Expression
Input parameters represents an entry parameter, and expression represents a formula. The input parameter is on the left side of the lambda operator, and the expression or statement block is on the right side of the lambda operator, and the lambda operator is read as "goes to"
//declare an appointment, with CLSS. Delegate intMyDelegate (inti);
delegate void Md2 (); classProgram {Static voidMain (string[] args) {MyDelegate MD = delegate (int x) //General appointment {return x * x; };MyDelegate MD = (x) + = x *x; //lambda-expression intA = MD (3); Console.WriteLine (a);
Md2 MD2 = () = {Console.WriteLine ("hello!!");}; //lambda-expression
MD2 (); } }
(x, y) = = {int result = X*y; Response.Write (Result. ToString ()); } Statement block {} When multiple statements are used
Where to use: For example: The set of Find (), FINDALL () parameter is the delegate
list<int> LL =Newlist<int> {1,2,3,4,5,6,7,8,9,9,0 }; foreach(varIteminchll. FindAll ((x) = x%2==0) {Console.WriteLine (item); }
LinQ c#3.0