A glance at C #3.0

Source: Internet
Author: User
First, I would like to take a look at an interview with Anders. After listening to the interview, I will see an article about LINQ by Dan Fernandez (Product Manager of Visual C #). Article And then aimed at the spec of C #3.0. it is estimated that the release will be completed within Ms. the demos about LINQ by Anders are cool.
The official definition of MS in LINQ is as follows:
LINQ stands for Language Integrated Query and in a nutshell, it makes query and set operations, like SQL statements first class citizens in. NET languages ages like C # and VB.
The meaning of LINQ is to integrate the query language, that is, the SQL statement in. net is called a first-class citizen. of course, this language is not only C #, but also all. net Language. of course, it is still necessary to lie in. net Framework. Program The clerk is tied to ms, and I am still playing fun in the afternoon. If Ms breaks down, what would happen to our friends.
A few paragraphs Code Cool: Using System;

Using System. query;

Using Danielfe;

 

Class Program

{

Static   Void Main ( String [] ARGs)

{

String [] Abunchofwords =   { " One " , " Two " , " Hello " ,

" World " , " Four " , " Five " } ;



VaR result =

From S In Abunchofwords // Query the String Array

Where S. Length =   5 // For all words with length = 5

Select S; // And return the string



// Printtoconsole is an extension method that prints the value

Result. Print ();

}

}

This editor is still C #1.1, and the keywords var, from, where, select. the above code is used to select a string of 5 from an array and print it.
So how to query from the database? The following code shows customers whose contract name (contactname) is 5 characters in length from the customer table (MERS mers) of the northwind database, and then prints the code. Is it cool? I don't know what C #3.0 will look like in the future, but from this code alone, DB. gettable <customs> () should be to get data from the database to the memory at one time, and then use where to filter. however, this efficiency is really worrying, and millions of customers can't stand it anymore. of course, this is just a few words of code. C #3.0 will certainly have a perfect solution for efficiency, and Anders will certainly do it. Using System;

Using System. query;

Using Danielfe;

Using System. Data. dlinq; // Dlinq is LINQ for Databases

Using Nwind; // Custom namespace that is tool generated

 

Class Program

{

Static   Void Main ( String [] ARGs)

{

Northwind DB =   New Northwind ( " Data Source = (local); initial catalog = northwind; Integrated Security = true " );

Table < MERs > Allcustomers = DB. gettable < MERs > ();

 

VaR result =  

From C In Allcustomers

Where C. contacttitle. Length =   5

Select C. contactname;

 

Result. Print ();

}

}

For more examples of LINQ code, see 101 linqsamples.
We know that C #2.0 adds generics, anonymous methods, iterators, and partial types. C #1.1 Based on C #3.0. What features will it add? After reading the spec of C #3.0, the new features are as follows:
1. implicitly typed local variables --- var, similar to VaR in Javascript, allows the variable type to be determined through the initial value.
2. Extension methods. allows you to extend existing types by adding additional methods to construct new types.
3.Lambda expressions is the evolution of anonymous methods. It provides enhanced type inference and adds the conversion to the delegate and Expression Tree.
4. Object initializers. Object Construction and initialization
5.Anonymous types
6.Implicitly typed Arrays
7.Query expressions
8.Expression trees
The 26-page spec describes the eight new or enhanced features in detail. Chapter 26 is available for C.
C #3.0 spec download

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.