View code
1 // 1. query all the girls in the list, whose ages are less than 18, and sort them in descending order. 2 // 2. query the students whose names start with "Wang" and whose length is 3. 3 Using System; 4 Using System. Collections. Generic; 5 Using System. LINQ; 6 Public Class Studylinq 7 { 8 Public Static Void Main () 9 { 10 List <people> List = New List <people> (); 11 List. Add ( New People () {name = " Kangxi " , Age = 18 , Sex = " Male " }); 12 List. Add ( New People () {name = " Yongzheng " , Age =20 , Sex = " Male " }); 13 List. Add ( New People () {name = " Qianlong District " , Age = 18 , Sex = " Male " }); 14 List. Add ( New People () {name = " Wang Xiaozhi " , Age = 23 , Sex = " Male " }); 15 List. Add ( New People () {name = " Wu Zetian " , Age = 17 , Sex = " Female " }); 16 List. Add ( New People () {name = " Cixi " , Age = 16 , Sex = " Female " }); 17 VaR Result = List. Where (P => P. age < 18 & P. Sex = " Female " ). Orderbydescending (P => P. Age ); 18 Foreach (PEOPLE In Result) 19 { 20 Console. writeline (A. Name + " " +A. Age ); 21 } 22 VaR Result1 = List. Where (P => P. Name. startswith ( " Wang " ) & P. Name. Length = 3 ); 23 Foreach (PEOPLE B In Result1) 24 { 25 Console. writeline (B. Name ); 26 } 27 } 28 Public Class People 29 { 30 Public String Name 31 { 32 Get ; Set ; 33 } 34 Public Int Age 35 { 36 Get ; Set ; 37 } 38 Public String Sex 39 { 40 Get ; Set ; 41 } 42 } 43 }