如何编写比较类以避免重复 [英] How to write compare class to avoid duplicates
本文介绍了如何编写比较类以避免重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hI,
我在构造函数类列表中有重复项
我需要避免重复
我正在尝试下面的事情
hI,
I am having duplicates in my constructor class list
I need to avoid the duplicates
I am trying something like below
class Compare : IEqualityComparer<PGNsegmentTxMap>
{
public bool Equals(PGNsegmentTxMap x, PGNsegmentTxMap y)
{
return x.segmentTx == y.segmentTx && x.PGN == y.PGN;
}
public int GetHashCode(PGNsegmentTxMap codeh)
{
return codeh.segmentTx.GetHashCode();
}
}
for(int i=0;i<database.Count;i++)
{
PGNsegmentMapLists.Add(new PGNsegmentTxMap(database1[i], database[i]));
}
PGNsegmentTxMap[] products = PGNsegmentMapLists.ToArray();
IEnumerable<PGNsegmentTxMap> noduplicates = products.Distinct(new Compare());
但我没有得到任何数据到noduplicates
任何人都可以帮我解决这个问题吗?
谢谢
John
But I am not getting any data into noduplicates
Can anyone help me in solving this???
Thanks
John
推荐答案
HI,
请尝试以下链接示例
http://msdn.microsoft.com/en-us/library /ms131190(v=vs.110).aspx [ ^ ]
这篇关于如何编写比较类以避免重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文