I have a DataTable which I get by an upload of CSV document from the user and has columns, rows like that:
Email Age Team
x@x.com 25 BarcelonaFC
y@y.com 32 BesiktasJK
z@z.com 18 Napoli
y@y.com 19 Boca Juniors
x@x.com 36 Internazionale
I need to filter that datatable before I insert it into the database. Email column should be unique. So I need to filter that datatable so that I get as a result eliminating 2 rows. I do not want to use LINQ, but if it is only solution, its ok.
Email Age Team
x@x.com 25 BarcelonaFC
y@y.com 32 BesiktasJK
z@z.com 18 Napoli
You can create a
HashSet<string>holding email addresses, then loop backwards through the table, add the email address for each row to the hashset, and, if it’s already there (ifAddreturns false), remove the row.