我试图使用DISTINCT我的名单上stationList
但好像我做错了什么,因为我没有得到明显的列表。我将如何获得Value
中不同的地方,我在那里设置stationList
。获取不同的名称
foreach (StationCategory stationCategory in productCatalog.Programming.StationCategory)
{
StringBuilder stationList = new StringBuilder();
foreach (Station station in stationCategory.Station.Distinct())
{
stationList.Append(station.StationName + ",");
}
offer.FeatureList.Add(new Feature() { FeatureName = "<b>" + stationCategory.CategoryName + "</b>", Value = stationList.ToString().TrimEnd(',') });
}
你没有得到什么?什么是“Station”,它包含什么,以及你如何比较平等?请发布*相关*代码,您发布的内容显示了对类别的迭代。邮政编码实际上重现问题 –
以应用不同,您需要一个标准来定义独特性。看看这个[post](http://stackoverflow.com/questions/10255121/get-a-list-of-distinct-values-in-list)。我建议尝试 –
后的“GroupBy”回答如果工作站可以在不同类别中重复,则需要用一个productCatalog.Programming.StationCategory.SelectMany替换2个'foreach'循环(sc => sc.Station ).Distinct()' – KMoussa