Click here to Skip to main content
15,905,682 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using a constructor to place the details of excel rows together

C#
for(int i=0;i<database.Count;i++)
           {
                            
               PGNsegmentMapList.Add(new PGNsegmentTxMap(database1[i], database[i]));

           }



Constructor:
C#
public class PGNsegmentTxMap
    {
         //string pgn;

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

       

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



Now some of the details of the constructor are repeated. How can I eliminate the repeated details of this list class.
Posted

1 solution

If you mean that you don't want duplicate PGNsegmentTxMap entries in your list, then create an EqualityComparer and use Distinct to remove duplicates: Distinct Linq Method[^]
 
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