Find duplicate and remove from List<T> by LINQ

  • Thread starter Thread starter Sudip_inn
  • Start date Start date
S

Sudip_inn

Guest
//if duplicate data found then remove duplicate data by LINQ
xmlDocTargetFile = XDocument.Load(strFilePath);

//removing duplicate data
xmlDocTargetFile.Descendants("TickerBrokerDateFormatMap").GroupBy(row =>
new
{
StandardDate = row.Element("StandardDate").Value,
Broker_Id = row.Attribute("Broker_Id").Value,
BrokerTab_Id = row.Attribute("BrokerTab_Id").Value
})
//.Where(grp => grp.Count() > 1)
.SelectMany(m => m.Skip(1)).Remove();

//save file again
xmlDocTargetFile.Save(strFilePath);

The above code worked when i deal with xml file and use XDocument class but when try to do the same thing using List<T>

then Remove() function was not available.

suppose i stored employee data in List<T> and want to remove duplicate employee based on EmployeeID and DepartmentID.

how to achieve the same this way using Skip(1) and Remove()

thanks

Continue reading...
 
Back
Top