//实例代码如下:
// DataTable中排除重复项
IEnumerable<DataRow> r = dt.AsEnumerable().Distinct(new RowLocationComparer());
if (r != null && r.Count() > 0)
{
foreach (var item in r)
{
//操作重复的响
}
}
/// <summary>
/// 取重复DataTable 行
/// </summary>
public class RowLocationComparer : IEqualityComparer<DataRow>
{
public bool Equals(DataRow r1, DataRow r2)
{
return r1["LOCATION_ID"].ToString().Equals(r2["LOCATION_ID"].ToString());
}
public int GetHashCode(DataRow obj)
{
return obj.ToString().GetHashCode();
}
}
//Ilist 排除重复项
ComputerNew com = new ComputerNew();
IList<V_TACCSTOCK_UPDATE> taccstocksList = taccstocks.Distinct(com).ToList<V_TACCSTOCK_UPDATE>();//排除重复的 店铺
public class ComputerNew : IEqualityComparer<V_TACCSTOCK_UPDATE>
{
#region IEqualityComparer<V_TACCSTOCK_UPDATE> Members
public bool Equals(V_TACCSTOCK_UPDATE x, V_TACCSTOCK_UPDATE y)
{
return x.LOCATION_ID.Equals(y.LOCATION_ID);
}
public int GetHashCode(V_TACCSTOCK_UPDATE obj)
{
return obj.LOCATION_ID.GetHashCode();
}
#endregion
}
DataTable,IList中排除重复项
最新推荐文章于 2021-03-26 17:41:26 发布