score:15
Accepted answer
var distinctItems = myList.GroupBy(x => x.prop1).Select(y => y.First());
score:1
You can also use morelinq DistinctBy:
distinctItems = myList.DistinctBy(x => x.prop1).ToList();
or with several properties:
distinctItems = myList.DistinctBy(x=> new { x.prop1, x.prop2}).ToList();
Source: stackoverflow.com
Related Articles
- How to remove duplicates from a list of custom objects, by a property of the object
- Get those elements from a List of custom class objects whose one property value is parseable to double
- How to remove (via linq) duplicates from a List of objects
- Remove objects, and child objects from a list in C# where they match an object property in another list
- GroupBy to remove duplicates from IEnumerable list of objects
- Remove duplicate objects with lowest Num property from list
- C# filter out duplicates from list of custom objects based on list attribute
- Remove duplicates from the list with lists as objects
- Remove items from list that intersect on property using Linq
- List<T> Where T is custom object. Remove duplicates by property
- Remove duplicates from list based on multiple fields or columns
- Getting unique values from a list of objects with a List<string> as a property
- Remove duplicates from DataTable and custom IEqualityComparer<DataRow>
- How do you remove trailing objects from a list with linq?
- Lambda or LinQ expression to remove certain objects from List
- Remove objects with duplicate properties from List
- How to select objects from a list that has a property that matches an item in another list?
- Linq to select list of items from custom nested list of objects
- Best way to remove elements from list field of list objects
- Using linq group by to get from a list of objects with a DateTime property to a list with an interval StartDate, EndDate
- Get the objects with the maximum value for a specific property from a list using LINQ
- LINQ to XML - list of custom objects with attributes from parent
- Select list of objects from navigation property in Entity Framework Core
- How can I get distinct objects extracted from a property of a list of objects?
- Cannot retrieve property from list of objects
- How to get only objects from list where property x is not null in C#
- LINQ to remove objects from a list of objects based on another list of objects
- Select objects from a list using LINQ based on a property
- C# linq remove duplicates from the top and bottom of the list and keep the duplicates in the middle
- Need to return an object with the lowest property value from List of objects
- Specified cast is not valid while fetching column details from SQL Server
- Sorting a List with OrderBy
- Equality Comparison with Multiple Instances/IEqualityComparer problems in LINQ
- Converting SQL to Linq query
- Linq Group By and merge rows
- Create a list from pairwise comparison
- Linq to Objects - Left Outer Join Distinct Object Property Values to an Aggregate Count
- How to perform double include on two levels of depth?
- Query values in a Dictionary<ObjectId, Class> using LINQ?
- Querying EF and saving results (records) into a list?
- Apply a callback to a list of items with LINQ
- How to pass a string from LINQ query to ViewBag
- Return list using select new in LINQ
- How to use LINQ remove a subset of list with certain criteria?
- Order List in same order as another list
- Linq: Xml to IEnumerable<KeyValuePair<int, string>> deferred execution?
- Linq Query using Case statement and concatenate special character
- Linq to sql to return related data
- List mapping manually
- Cannot implicitly convert type '.List<AnonymousType#1>' to '.List<WebApplication2.Customer>'