Linq Distinct List 去重复

//调用
 return producePlantlst.Distinct(new item_collection_DistinctBy_item1()).ToList();

//方法
    public class item_collection_DistinctBy_item1 : IEqualityComparer<FMDS_ProducePlantInfo>
    {

        public bool Equals(FMDS_ProducePlantInfo x, FMDS_ProducePlantInfo y)
        {
            if (x.TaskAreaName == y.TaskAreaName && x.FarmPlotName == y.FarmPlotName && x.PlantYear == y.PlantYear && x.FarmerName == y.FarmerName && x.FarmProductClassName == y.FarmProductClassName)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public int GetHashCode(FMDS_ProducePlantInfo obj)
        {
            return 0;
        }
    }

 

posted @ 2014-04-18 15:23  beau  阅读(743)  评论(0编辑  收藏  举报