我的对象长这个样子
我有一个类中的对象列表,其中数据如下:
我想筛选这个列表,以便获得以下输出。
但是这样只会返回第一个元素的结果,如下所示:
public class Region
{
public Region();
public string City { get; set; }
public int PostCode { get; set; }
public string WfRegion { get; set; }
}
我有一个类中的对象列表,其中数据如下:
Rodney , 7845 , Auckland
Rodney , 3435 , Auckland
Rodney , 4566 , Auckland
Rodney , 3445 , North Island
我想筛选这个列表,以便获得以下输出。
Rodney , 7845 , Auckland
Rodney , 3445 , North Island
无论邮政编码如何,都需要列出城市和地区的所有可能组合。
我写了一些类似于以下的查询:
var cities = regionsData.DistinctBy(p =>
p.WfRegion).DistinctBy(p=>p.PostCode).DistinctBy(p => p.City).ToList();
但是这样只会返回第一个元素的结果,如下所示:
Rodney , 7845 , Auckland
我该如何解决这个问题?