class ProductComparare : IEqualityComparer<YEWULIANG>
        {
            private Func<YEWULIANG, object> _funcDistinct;
            public ProductComparare(Func<YEWULIANG, object> funcDistinct)
            {
                this._funcDistinct = funcDistinct;
            }
            public bool Equals(YEWULIANG x, YEWULIANG y)
            {
                return _funcDistinct(x).Equals(_funcDistinct(y));
            }
            public int GetHashCode(YEWULIANG obj) { return this._funcDistinct(obj).GetHashCode(); }
        }

 

使用如下:

List<YEWULIANG> list=new List<YEWULIANG> (){

  new YEWULIANG {name="1",age=12} ,

  new YEWULIANG {name="1",age=13} ,

  new YEWULIANG {name="2",age=14} ,

}

//使用后

var listCNAME = list.Distinct<YEWULIANG>(new ProductComparare(m => m.c_name)).ToList();

listCNAME里面的对象为

 new YEWULIANG {name="1",age=12} ,

   new YEWULIANG {name="2",age=14} ,

 

相关文章:

  • 2021-12-03
  • 2022-12-23
  • 2022-03-06
  • 2021-10-25
  • 2021-06-07
  • 2022-02-25
  • 2022-12-23
  • 2021-11-23
猜你喜欢
  • 2021-12-11
  • 2021-12-03
  • 2022-12-23
  • 2021-12-03
  • 2021-10-16
  • 2021-10-09
相关资源
相似解决方案