【发布时间】:2011-09-27 15:50:18
【问题描述】:
我有以下清单:
class Person
{
public String Name { get; set; }
public String LastName { get; set; }
public String City { get; set; }
public Person(String name, String lastName, String city)
{
Name = name;
LastName = lastName;
City = city;
}
}
...
personList.Add(new Person("a", "b", "1"));
personList.Add(new Person("c", "d", "1"));
personList.Add(new Person("e", "f", "2"));
personList.Add(new Person("g", "h", "1"));
personList.Add(new Person("i", "j", "2"));
personList.Add(new Person("k", "l", "1"));
如何检索与城市名称不同的人员列表?
预期结果:
与城市名称不同的列表(人)的数组/集合:
result[0] = List<Person> where city name = "1"
result[1] = List<Person> where city name = "2"
result[n] = List<Person> where city name = "whatever"
【问题讨论】:
-
你的意思是姓氏!=城市吗?
-
不,我不想要一个包含所有包含 1 作为城市和另一个包含 2 作为城市的 Persons 的列表...
-
您是否要按城市对该人进行分组?
-
我也很困惑。您是想按城市统计人数,还是按城市分组?