List<Person> lstPerson = new
List<Person>();
013 | lstPerson.Add( new Person(1, "puma" , 10)); |
014 | lstPerson.Add( new Person(2, "F6 Team" , 20)); |
015 | lstPerson.Add( new Person(3, "ASP.NET" , 30)); |
016 | lstPerson.Add( new Person(4, "Dotblogs" , 40)); |
019 | this .GridView1.DataSource = lstPerson; |
020 | this .GridView1.DataBind(); |
026 | Response.Write( "找出Name='puma'的Person→ " ); |
027 | Response.Write(lstPerson.Find( delegate (Person p) { return p.Name == "puma" ; }).ToString() + "<p>" ); |
033 | Response.Write( "找出Age>10的數目→ " ); |
034 | Response.Write(lstPerson.FindAll( delegate (Person p) { return p.Age > 10; }).Count.ToString() + "<p>" ); |
040 | Response.Write( "檢查Name='F6'是否存在→ " ); |
041 | Response.Write(lstPerson.Exists( delegate (Person p) { return p.Name == "F6" ; }).ToString() + "<p>" ); |
047 | Response.Write( "<p>依Name升冪排序↑<br/>" ); |
048 | lstPerson.Sort( delegate (Person p1, Person p2) { return Comparer< string >.Default.Compare(p1.Name, p2.Name); }); |
049 | foreach (Person p in lstPerson) |
051 | Response.Write(p.ToString() + "<br/>" ); |
058 | Response.Write( "<p>依Name降冪排序↓<br/>" ); |
059 | lstPerson.Sort( delegate (Person p1, Person p2) { return Comparer< string >.Default.Compare(p2.Name, p1.Name); }); |
060 | foreach (Person p in lstPerson) |
062 | Response.Write(p.ToString() + "<br/>" ); |