Click here to Skip to main content
15,850,360 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public class PGNsegmentTxMap
    {

         string pgn;
         public string segmentTx { get; set; }
        

         
         public string PGN
         {
             get
             {
                 if (!String.IsNullOrEmpty(pgn))
                     return pgn.ToUpper();
                 else
                     return string.Empty;
             }

             set { pgn = value; }
         }
        public PGNsegmentTxMap(string pgn, string segmentTx)
        {
            this.segmentTx = segmentTx;
            this.pgn = pgn;
        }
    }

     #endregion





     class ProductComparer : IEqualityComparer<PGNsegmentTxMap>
     {
         // Products are equal if their names and product numbers are equal. 
         public bool Equals(PGNsegmentTxMap x, PGNsegmentTxMap y)
         {

             //Check whether the compared objects reference the same data. 
             if (Object.ReferenceEquals(x, y)) return true;

             //Check whether any of the compared objects is null. 
             if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
                 return false;

             //Check whether the products' properties are equal. 
             return x.segmentTx == y.segmentTx && x.PGN == y.PGN;
         }
         public int GetHashCode(PGNsegmentTxMap product)
         {
             //Check whether the object is null 
             if (Object.ReferenceEquals(product, null)) return 0;

             //Get hash code for the Name field if it is not null. 
             int hashProductName = product.segmentTx == null ? 0 : product.segmentTx.GetHashCode();

             //Get hash code for the Code field. 
             int hashProductCode = product.PGN.GetHashCode();

             //Calculate the hash code for the product. 
             return hashProductName ^ hashProductCode;
         }

         

     }
Posted
Updated 10-Feb-14 4:02am
v3

1 solution

C#
for (int i = 0; i < PGNsegmentMapLists.Count; i++)
        {
            PGNsegmentTxMap[] products = PGNsegmentMapLists[i];
        }

        PGNsegmentTxMap[] products = PGNsegmentMapLists.ToArray();
 
Share this answer
 
Comments
Member 10408451 10-Feb-14 8:45am    
Hi,
It works fine
But when I am trying like below
IEnumerable<PGNsegmentTxMap> noduplicates = products.Distinct(new ProductComparer());
it is not giving distinct values of products into noduplicates
Can you help me in solving this
Karthik_Mahalingam 10-Feb-14 8:55am    
change this ProductComparer such a way that it will compare the exact duplicates..
or post the ProductComparer
Member 10408451 10-Feb-14 9:04am    
Hi,
Now I updated my question with class and productComparer
please check it

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