標籤:
List元素類:
public class MultiPointSearchingRet { public int ID { get; set; } public string PlateNumber { get; set; } public int VehicleBrand1 { get; set; } public string BrandName { get; set; } }
實現了IEqualityComparer的比較類:
public class MultiPointSearchingRetComparer : IEqualityComparer<MultiPointSearchingRet> { public bool Equals(MultiPointSearchingRet x, MultiPointSearchingRet y) { return x.PlateNumber == y.PlateNumber && x.VehicleBrand1 == y.VehicleBrand1; } public int GetHashCode(MultiPointSearchingRet obj) { return obj.ID.GetHashCode(); } }
調用:
List<MultiPointSearchingRet>[] tmpLst = new List<MultiPointSearchingRet>[10]; List<MultiPointSearchingRet> retLst = new List<MultiPointSearchingRet>(); //略 for (int i = 0; i < length; i++) { if (i == 0) retLst = tmpLst[i]; else retLst = retLst.Intersect(tmpLst[i], new MultiPointSearchingRetComparer()).ToList(); }
c#List結合IEqualityComparer求交集