2 points:
A collection of 1.LINQ operations must implement the IEnumerable interface, so that a collection that implements the interface before 3.0 is converted to a LINQ collection by either the cast or the TypeOf method;
2. Query and lame the expression can be used together. Which is convenient to use, they only when the first use of the real query;
List<employee> ils = new list<employee> () {new Employee () {idcode= "Jack5", age=2 0,littlename= "AB"}, new Employee () {idcode= "mike444", Age=12,littlename= "AA"}, new Employee () { Idcode= "Mary5", Age=12,littlename= "Zs"}, new Employee () {idcode= "sm5555", Age=67,littlename= "YB"}, New Employee () {idcode= "som", age=67,littlename= "Cr"}}; ArrayList als = new ArrayList () {new Department () {name= "Jack", Depname= "Fuji Kang"}, N EW Department () {name= "Jack", Depname= "WA"}, new Department () {name= "Mary", depname= "totem Message"}, new D Epartment () {name= "sum", depname= "Move"}, new Department () {name= "Soom", depname= "union"}}; #region Search the third chapter, LINQ technical Details//with into the group by sentence var va = from C in ILS Group C by New {c.littlename, c.age} into G select New {Name = G.key, Agec = G.count ()}; var va1 = ils. GroupBy (p = new {p.littlename, p.age}). Select (p = = new {name = P.key, Agec = P.count ()}); Display variable type var vart = from C in ILS join Department d in ALS on C.idcode equals d.name Select New {age = c.age, depname = D.depname}; var varT1 = ils. Join (ALS. Cast<department> (), C = c.idcode, p = = P.name, (c, p) = = new {age = c.age, depname = P.depname}); Join syntax var varjoin = from C in ILS join Department d in ALS On C.idcode equals D.name into AO select new {c.idcode, sum = AO . Sum (P = p.depname.length)}; var varJoin1 = ils. GroupJoin (ALS. Cast<department> (), a = A.idcode, B = b.name, (b, a) = = new {b.idcode, sum = A.count ()}); Let and where syntax var varlet= from C in ils let names = C.idcode + ":" + c.littlename where names. Length > 5 Select New {c.age, names}; var varLet1 = ils. Select (A = new {A, names = A.idcode + ":" + A.littlename}). Where (p = p.names.length > 5). Select (b = new {b.a.age, b.names}); Generator language (multiple from), the sentence-by-phrase var Varselmany = from A in ILS from B in ALS. Cast<department> () a.age, a.department descending se Lect New {a.idcode, A.littlename, A.age, b.depname}; var varSelMany1 = ils. SelectMany (p = als). Cast<department> (). Select (A = new {p.age, a.depname})). OrderByDescending (A = a.age). ThenByDescending (a = a.depname); GROUP BY var vargroup = from P in ILS group p by p.age into a Select A.key + ":" + als. capacity; #endregion #region delay operator details//The ArgumentNullException//select,where both have two prototypes, and the other prototype has index parameters var varwhere = ils. Where ((p, i) = i < 2); The division operator take var vartake = ils. Take (2); TakeWhile will jump out of var vartakewhile = ils as long as the condition does not conform. TakeWhile (p, q) = p.idcode.length > 4); Skip and take complementary var varskip = ils. Skip (2); SkipWhile and TakeWhile are complementary var varskipwhile = ils. SkipWhile ((A, I) = a.idcode.length > 5 && i < 3); The string union operator var Varconcat = ils. Take (2). Concat (ILS. Skip (2)); Concat can only chain two sequences, when the series of multiple sequences can be used selectmany; var varSelectMany1 = new[] {ils. Take (1), ils. Skip (1)}. SelectMany (s = = s); Sort operation, the second prototype can be added, the comparison device, two order with thenby,orderbydesding like var Varorderby = ils. OrdeRby (p = p.idcode.length); Reverse reverse sequence outputs//join and joingroup p119 ienumerable<igrouping<string,employee>> items = Ils. GroupBy (p = p.littlename); ienumerable<igrouping<string,department>> items1= ils. GroupBy (p = p.idcode, q = q.department); The set operator distinct,union (and sets the concat), intersect (the sequence of repeated elements after the connection), except (the element that is repeated with itself in the delete reference) var CA = ils. Distinct (); list<employee> ils1 = ils. Take (2). Tolist<employee> (); Ils1. ADD (New Employee () {Idcode = "I add", age = Littlename = "Xixi"}); foreach (Var v in ILS). Except (ILS1)) {Console.WriteLine (v.littlename); }//element operator var ilsdefaultifempty = ils. Where (p = = P.idcode = = "hehe"). DefaultIfEmpty (). First (); var ilsDefaultIfEmpty1 = ils. Where (p = = P.idcode = = "hehe"). DefaultIfEmpty (New Employee () {idcode= "Heheid"}). First (); //Generate operator Enumerable method Range,repeat, ienumerable<int> enumrange = Enumerable.range (2, 20); foreach (int i in Enumrange) {Console.WriteLine (i); }//p145 String str = string. Empty; Cast,oftype,asenumerable () [Will sequence the program column, appropriate for LINQ to SQL] #endregion
LINQ Learning Summary-Reference LINQ technical details