First look at a very simple LINQ for example, an int array for less than five figures, and in accordance with the size of the order:
Class Program
(
Static void Main (string [] args)
(
Int [] arr = new int [] (8, 5, 89, 3, 56, 4, 1, 58);
Var m = from n in arr where n <5 orderby n select n;
Foreach (var n in m)
(
Console.WriteLine (n);
)
Console.ReadLine ();
)
)
Apart from the above code LINQ query syntax, the other we are familiar with the syntax, and LINQ query syntax with the SQL query syntax is met, in addition to setting priorities.
Q: Why LINQ query syntax is from the beginning of the keyword, instead of the beginning of the select keywords? Select the beginning of this wording with the wording closer to SQL, and more understandable way?
A: In simple terms, in order to intelligent perception IDE (Intelisence) this function, select keywords on the back.
Beginning to select programming languages to write LINQ query syntax is not a no-show, if you use the 2005 version of the VB9 CTP, then VB9 LINQ query syntax is the keyword in front of select, but select keyword in front of doing the smart Perception (Intelisence) when very big. After weighing Microsoft IDE group determined from the keyword in the front.
For example: You see http://blog.joycode.com/saucer/archive/2005/09/16/63513.aspx this blog, then VB9 LINQ query syntax or select the parameters first. But later changed VB9 test version of C # with the same approach, from a keyword in the front.
A more detailed explanation from the head assembly
Suppose you want to write this code: Select p.Name, p.Age From p In persons Where xxx, is a code input characters.
We wrote p in persons, the type of p is impossible to speculate, therefore, write Select p. when Name attributes such as intelligence tips that would not pop up.
This brought about the need to write From this, and come back to write Select.
Microsoft IDE group decision after reconsideration, if not put behind the Select wrote. So programming language in the wording on this to determine wrote.
VB9 of this change can see this blog:
Select / From vs. From / Select revisited ...
We look at a slightly more complex LINQ Enquiries:
We set out in the language of string, we hope that the characters in accordance with the length of classification set out to achieve the following code:
Static void Main (string [] args)
(
Languages string [] = ( "Java", "C #", "C ++"," Delphi," "VB.net," "VC.net", "C + + Builder," "Kylix", "Perl", "Python" );
Var query = from item in languages
Orderby item
Group item by item.Length into lengthGroups
Orderby lengthGroups.Key descending
Select lengthGroups;
Foreach (var item in query)
(
Console.WriteLine ( "strings of length (0)", item.Key);
Foreach (var val in item)
(
Console.WriteLine (val);
)
)
Console.ReadLine ();
)
The keywords that will be into the results of inquiries ago as a follow-up query generator, here is used in conjunction with the group by.
LINQ not in the Group by SQL with the Group by confusion, SQL Because it is two-dimensional structure of the Group by the logic structure of the two-dimensional constraint, not as the Group by LINQ so flexible. |