8,497
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 去除Map集合中重复的方格
/// </summary>
public class MapListDistinct : IEqualityComparer<Map>
{
public bool Equals(Map x, Map y)
{
if (x == null || y == null)
return false;
if (x.PointX == y.PointX && x.PointY == y.PointY)
return true;
else
return false;
}
public int GetHashCode(Map obj)
{
if (obj == null)
return 0;
else
return obj.PointX.GetHashCode() ^ obj.PointY.GetHashCode();
}
}
其中
if (x.PointX == y.PointX && x.PointY == y.PointY)和obj.PointX.GetHashCode() ^ obj.PointY.GetHashCode();
这两段内容是去除重复重点,将其修改成你需要比较的字段
使用方法:
//去除重复的方格
mapsList = mapsList.Distinct(new MapListDistinct()).ToList();
query.groupby(p=>new{ p.GoodsName,p.UserName}).Select(p=>g.First());