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 Query
- How to remove duplicates from a list of custom objects, by a property of the object
- How to remove (via linq) duplicates from a List of objects
- How to query the average from a certain property in an Entity and return it in a List of List of objects in LINQ?
- Remove duplicates from the list with lists as objects
- How do I get the objects from a list of objects which contain a duplicate property inside of another list in the object?
- How do you remove trailing objects from a list with linq?
- How to select objects from a list that has a property that matches an item in another list?
- How to select all the values of an object's property on a list of typed objects in .Net with C#
- How to iterate at elements from a sub list and then remove the sub list from the list? With great performance
- How to remove from one list all the items in another?
- Get those elements from a List of custom class objects whose one property value is parseable to double
- C# how to group List by objects with the same property values
- Get the objects with the maximum value for a specific property from a list using LINQ
- How can I get distinct objects extracted from a property of 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
- How to get only objects from list where property x is not null in C#
- How to remove from the list the items that have parents in the same list
- 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
- how to remove objects from list by multiple variables using linq
- How can I return a object with the sum of all objects from a list using Linq?
- How to filter linq query based on all of the values of one property from another list
- Return the number of times a string occurs as a property in a list of custom objects
- Remove duplicate objects with lowest Num property from list
- How to get the property from a list of object that is a string with the lowest numeric value
- How do I remove objects with a combination of duplicate of two properties from List with linq?
- How to remove duplicates from a list of nested objects?
- Take max date row from duplicates and remove duplicates in the list using linq
- How to take the Max value from a List of object where the same objects exists with many duplicate rows
More Query from same tag
- Linq Double contains
- Change item in collection with LINQ
- call xml tag value with linq
- Filter a list of objects using a property that is another list. Using linq
- Any LINQ alternative for loop in reflection?
- How to assign key and count to two different labels asp.net
- Entity Framework query table name dynamically based on input parameter
- retrieve data to textboxt using LINQ to SQL
- List<Object> inline initialisation order not maintained
- How to get attribute value using LINQ to XML?
- Add additional fields to Linq group by
- NHibernate select query
- How can convert a For statement into LINQ
- C# Linq to entities - How to select only records which have all references from array
- Struggling with .ToList() returing an EntitySet<...>, not an IList<..>
- Sql query to Linq using subquery
- GroupBy in LINQ with string[] array
- Check if a query contains things out of the list
- How to split string before Binding in repeater
- Initializing Lookup<int, string>
- sum distinct values from a column in datagridview
- Why doesn't Select() convert a IEnumerable<dynamic> to IEnumerable<StrongType>?
- Obtain ToTraceString() for IQueryable
- Join few tables without repeat same data
- copying double[] values into an entire column in a datatable rapidly
- Cannot retrieve object from inner dictionaries/lists
- Using ASP.NET WebService with javascript
- Dotnet EF Core Linq string contains in a list string split by comma
- DataGridView cell search using a LINQ query
- C# Linq SelectMany, returning entire object