1.创建compare类
using DCZY.Bean; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DCZY.Bean { public class HookPlanMonitorDeviceCompare : IEqualityComparer<HookPlanMonitorDeviceInfo> { public bool Equals(HookPlanMonitorDeviceInfo x, HookPlanMonitorDeviceInfo y) { if (x.Device.Name == y.Device.Name) { return true; } else { return false; } } public int GetHashCode(HookPlanMonitorDeviceInfo obj) { int hCode = obj.Device.Name.GetHashCode(); return hCode.GetHashCode(); } } }
2.调用
List<HookPlanMonitorDevice> devicecollection = devicecollection.Distinct(new HookPlanMonitorDeviceCompare()).ToList();