namespace Test
{

    class Program
    {

        private static List<Student> list1 = new List<Student>();      //声明一个用于放置初始值的集合  注:必须声明List类型而不是IList接口类型
        private static List<Student> list2 = new List<Student>();      //用户存放筛选结果
        static void Main(string[] args)
        {

            //声明实例化student对象
            Student stu1 = new Student("aa", 10);

            Student stu2 = new Student("bb", 13);

            Student stu3 = new Student("cc", 15);

            Student stu4 = new Student("dd", 18);

            //向集合中添加对象
            list1.Add(stu1);

            list1.Add(stu2);

            list1.Add(stu3);

            list1.Add(stu4);

            Console.WriteLine(list1.Find(delegate(Student stu) { return stu.Age > 12; }).Name);            //返回筛选满足条件的第一个对象
            list2 = list1.FindAll(delegate(Student stu) { return stu.Age > 12; });          //对泛型集合进行筛选
            //遍历结果
            foreach (Student stu in list2)
            {

                Console.WriteLine(stu.Name);

            }

        }

    }

}

相关文章:

  • 2021-06-29
  • 2021-07-08
  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2021-08-18
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-12
  • 2021-11-14
  • 2021-09-03
  • 2021-11-15
  • 2022-12-23
  • 2021-07-12
相关资源
相似解决方案