C#_ViewModel中通過 hash 去重
阿新 • • 發佈:2019-01-09
ViewModel中通過 hash 去重
public class Order_Detail_ViewModel : Object{ public string SAP_PickLocation { get; set; } public string SAP_Material_ID { get; set; } public string StorageSectionCode { get; set; } public override bool Equals(object obj){ var obj1 = obj as Order_Detail_ViewModel; if(obj1 == null) { return false; } return this.SAP_Material_ID == obj1.SAP_Material_ID && this.SAP_PickLocation == obj1.SAP_PickLocation && this.StorageSectionCode == obj1.StorageSectionCode; } public override int GetHashCode(){ return (SAP_PickLocation + SAP_Material_ID + StorageSectionCode).GetHashCode(); } }
然後 ().distinct()