C# List<T> Lambda取某一属性组合为新List(Select),并去重(Distinct)

People p1 = new People() { Age = 10, Name = "张三", Birth = Convert.ToDateTime("1966-10-1") };
People p2 = new People() { Age = 18, Name = "李四", Birth = Convert.ToDateTime("1977-10-2") };
People p3 = new People() { Age = 12, Name = "王二", Birth = Convert.ToDateTime("1988-10-3") };
List<People> list = new List<People>();
list.Add(p1);
list.Add(p2);
list.Add(p3);

List<People> lstType = list1.Select(t => t.Name).Distinct().toList();
posted @ 2022-03-11 10:45  673613920  阅读(361)  评论(0编辑  收藏  举报