1. Learn about LINQ.

Source: Internet
Author: User

Summary:

The first article to learn about LINQ, understand what it is about, and understand the knowledge related to Kerberos and a simple examples of Kerberos.

This series is my study notes, source: http://www.cnblogs.com/lovecherry/

Content:

LINQ is a language Integrated Query Based on relational data. It is used to query relational data managed in the form of objects.

LINQ includes: LINQ to SQL, LINQ to XML, LINQ toobjects, and LINQ to dataset.

I only want to learn about LINQ to SQL here. I can abbreviated this as "SCSI. It is purely personal behavior. Do you know if this is a standard ?!

 

Among them, LINQ to objects is the core, and LINQ to XML is also widely used. While I think it is the most easy to get started and commonly used.

 

LINQ is in C #3.0, so it must be learned in vs2008 or vs2010. I use vs2010.

 

Here we want to know some new things in C #3.0:

 

1. var Declaration: the newly added item declares the implicit type local variable. Because it is an implicit type, it must be assigned a value during declaration so that the system can determine the type. This usage is similar to that in Js.

2. The anonymous types commonly used in the Air Security Service are as follows:

Varuser = new {login = "admin", Pwd = 123456}; // No need to display the definition

3. Extension Method:

Extension methods can only be defined in static classes and are static methods. This will be used later.

4. Lambda expressions:

(Parameter list) => expression or statement Block

 

A simple example:

 

Create a new leleapplication in vs2010 (or vs2008) and you will find that the. CS file will have more reference space than vs2005: using system. LINQ ;. This is only available after C #3.0.

Because there are few codes, they are all pasted:

Usingsystem;

Using system. Collections. Generic;

Using system. LINQ;

Using system. text;

 

Namespace sqdemo1conapp

{

Public class person

{

Public String username {Get; set ;}

Public int age {Get; set ;}

}

Class Program

{

Static void main (string [] ARGs)

{

VaR persons = new list <person> {

New person {username = "A", age = 19 },

New person {username = "B", age = 20 },

New person {username = "C", age = 21}

};

// Select username. toupper () from persons where age> = 20

// Var selectperson = from P in persons where P. age> = 20 selectp. username. toupper ();

VaR selectperson = Persons. Where (P => P. age> = 20). Select (P => P. username. toupper ());

 

Foreach (var p in selectperson)

Console. writeline (P );

Console. readkey ();

}

}

}

 

Where varselectperson = from P in persons where P. age> = 20 selectp. username. toupper ();

Equivalent to varselectperson = Persons. Where (P => P. age> = 20). Select (P => P. username. toupper ());

It is similar to select username. toupper () frompersons where age> = 20 in T-SQL.

Note => and> = indicate different meanings.

It is said that the T-SQL 90% function can be implemented with only some complex functions. The SELECT statement is written at the end, which is not the same as that in T-SQL.

 

Download source code here

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.