C#_ViewModel中通过 hash 去重

版权声明:本文为Martin原创文章,未经Martin允许不得转载。 https://blog.csdn.net/qq_36279445/article/details/83791965

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()

猜你喜欢

转载自blog.csdn.net/qq_36279445/article/details/83791965