Remove duplicate objects from Collection based on some properties

var withoutDuplicates = reorderTitles.GroupBy(z => z.NewOrder).Select(z => z.First()).ToList();

//reorderTitles is a collection and we are removing items NewOrder property.


var list = new List<SignUp>();

List<SignUp> distinctSignUp = list
.GroupBy(x => new {x.PersonId, x.VersionId} )
.Select(y => y.Last()).ToList();
//removing duplicates by PersonId and VersionId. And new keyword is import.  after new  ‘{‘ , ‘}’ also.

var duplicates = items.GroupBy(i => new {i.ValueA, i.ValueB})
.Where(g => g.Count() > 1).Select(g => g.Key);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s