c#遍历集合方法

using System;
using System.Collections.Generic;
using System.Linq;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            List<PersonClass> personList = new List<PersonClass>()
            {
                new PersonClass("张三",35, "男"),
                new PersonClass("李四",25, "女"),
                new PersonClass("王五",19, "女"),
                new PersonClass("赵六",33, "男"),
                new PersonClass("吴亦凡",18, "男"),
            };

            personList = personList.Where(p => p.sex == "男" && p.age >= 30).ToList();
            personList = personList.Select(p => p.sex == "男" && p.age >= 30).ToList();
            //foreach(var item in personList)
            //{
            //    Console.WriteLine(item.name + "," + item.age + "," + item.sex);
            //}

            //personList.ForEach(item =>
            //{
            //    Console.WriteLine(item.name + "," + item.age + "," + item.sex);
            //});
            Console.ReadKey();
        }
    }
}


版权声明:本文为qq_62693450原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。