我有一个名为Items
的类,它包含属性(Id、Name、Code、Price)
Items
列表中存在重复的条目。
例如:
1 Item1 IT00001 $100
2 Item2 IT00002 $200
3 Item3 IT00003 $150
1 Item1 IT00001 $100
3 Item3 IT00003 $150
如何使用linq在列表中去除重复项?
var set = new HashSet<int>(); var uniques = items.Where(x => set.Add(x.Id));
。这样做应该是违法的。 - nawfal