//去掉重复 var title = modelList.GroupBy(m => m.Title.ToLower().Trim()).Select(m => new { ID = m.FirstOrDefault().ID }); modelList = modelList.Where(m => title.Select(mo => mo.ID).Contains(m.ID)).ToList(); foreach (var item in modelList) { Console.WriteLine(item.ID + " " + item.Title); }
for (int i = 0; i < listmodeler.Count - 1; i++) { for (int j = i + 1; j <= listmodeler.Count; j++) { if (i != j) { if (listmodeler[i].Modelid == listmodeler[i + 1].Modelid) { listmodeler.Remove(listmodeler[i]); } } } }
//去掉重复数据 for (int i = 1; i < lter.Count + 1; i++) { int index = 0; //重复列数据标记 for (int j = i + 1; j < lter.Count() + 1; j++) { //此处判断重复列 if (lter[i - 1].OrderID == lter[j - 1].OrderID) { index++; //此处做相应的操作 lter.Remove(lter[i - 1]); } } //在一圈寻找结束后,判断,寻找的结果,根据结果来操作具体数据 if (index == 0) { } }
//定义一个类继承IEqualityComparer接口 public class OrderComparer : IEqualityComparer<ListOrder> { public bool Equals(ListOrder x, ListOrder y) { return x.OrderID == y.OrderID; } public int GetHashCode(ListOrder obj) { return obj.OrderID.GetHashCode(); } } //调用: AListOrder = AListOrder.Distinct(new OrderComparer()).ToList();