usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceconsoleapplication1{usingSystem.IO; Public classProgram { Public Static voidMain (string[] args) {List<Student> list =NewList<student> () {NewStudent () {Name ="Zhang San", age =8},NewStudent () {Name ="John Doe", age =9 } }; //ienumerable<t> satisfying the conditionsienumerable<student> x1 = list. Where (p = p.age >0); //ienumerable<string> satisfying the conditionsienumerable<string> x2 = list. Select (p =p.name); //the first element in the sequence, if not satisfied, returns the default (Student)Student x3 = list. Find (p = p.age <0); //all elements in the sequence are list<t> if not, the new list<t> is returnedlist<student> x4 = list. FindAll (p = p.age <0); //the first element in the sequence, if List==new list<t> (), throws an exceptionStudent x5 =list. First (); //The first element in a sequence, or default (T)Student x6 =list. FirstOrDefault (); List=NewList<student>(); X1= list. Where (p = p.age >0); X2= list. Select (p =p.name); X3= list. Find (p = p.age <0); X4= list. FindAll (p = p.age <0); X5=list. First (); X6=list. FirstOrDefault (); //List==null, throw all the exceptions.List =NULL; X1= list. Where (p = p.age >0); X2= list. Select (p =p.name); X3= list. Find (p = p.age <0); X4= list. FindAll (p = p.age <0); X5=list. First (); X6=list. FirstOrDefault (); } } Public classStudent { Public stringName {Get;Set; } Public intAge {Get;Set; } }}
Lamabda Where Select Find First and other differences