linq学習(LastとFirst)

4101 ワード

 
class Student
           {
               public string Name { get; set; }
               public int Score { get; set; }
               public string Sex { get; set; }
            }

List<Student> list = new List<Student>{
                new Student{ Name=" ",Score=96, Sex=" "},
                 new Student{ Name=" ",Score=80, Sex=" "},
                  new Student{ Name="Mery",Score=96, Sex=" "},
                   new Student{ Name="Mei",Score=85, Sex=" "}
                  
           };

 // 
            var s = list.First();
            Response.Write(s.Name);
            //   


            // 85, 
            var student2 = list.First(a=>a.Score>85 &&a.Sex==" ");
            Response.Write(student2.Name);
            //  Mary


            // 85 
            var student3 = list.Last(a => a.Score > 85);
            Response.Write(student2.Name);
            //  Mary