Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
hI,

I am having duplicates in my constructor class list
I need to avoid the duplicates
I am trying something like below

C#
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());



But I am not getting any data into noduplicates
Can anyone help me in solving this???


Thanks
John
Posted
Comments
BillWoodruff 11-Feb-14 5:29am    
The solutions to a similar problem here may help you:

http://www.codeproject.com/Questions/721418/Csharp-class-instance-comparison-distinct

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900