LINQ Select distinct from a List?

前端 未结 3 761
不知归路
不知归路 2021-01-18 14:41

I have the following list:


    class Person
    {
        public String Name { get; set; }
        public String LastName { get; set; }
        public Stri         


        
3条回答
  •  遇见更好的自我
    2021-01-18 15:06

    Judging by this comment: No, I wan't a list containing all the Persons that contains 1 as a city and another that contains 2 as a city...

    We can do something like this:

    var city1People = personList.Where(x => x.city == "1").ToList();
    var city2People = personList.Where(x => x.city == "2").ToList();
    

    if this is something more dynamic, like you're going to have N cities and want an individual list of people per city, you're going to need to return a collection of lists.

提交回复
热议问题