One of the LINQ to SQL in-depth learning series c#3.0 for the Enhancement of LINQ

Source: Internet
Author: User
Tags anonymous

To enable LINQ to be seamless and integrated with the C # language, Microsoft has added new features to c#3.0, which focuses on enhancing LINQ-related.

1, the VAR keyword, collection initialization, and anonymous types

2. LAMBDA expression

3. Partial (Partial) method

4. Extension method

5. Expression tree

1, the VAR keyword, collection initialization, and anonymous types

Var:

You can give local variables the inference of "type" var instead of an explicit type. The VAR keyword instructs the compiler to infer the type of the variable based on an expression to the right of the initialization statement. The inferred type can be a built-in type, an anonymous type, a user-defined type, a type defined in the. NET Framework class Library, or any expression. var simply represents the most appropriate type to be determined and assigned by the compiler. is different from the concept of Var in JavaScript. For example: var i = 5; After compiling i is an integral type, and int i=5; In many cases, Var is optional, and it only provides grammatical convenience.

Take a look at the following examples:

var i = 5;//int
var j = 23.56;//double
var k = "C Sharp";//string
var x;// 错误
var y = null;//错误
var z = { 1, 2, 3 };//错误

Object and Collection initializer:

Class User
{
public int ID {get; set;}
public string Name {get; set;}
public int Age {get; set;}
}
User user = new user ();
User. Id = 1;
User. Name = "LFM";
User. age = 22;

Related Article

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.