I have a collection called navigationList. This list holds customer objects.
A customer has a property called Town.
The list holds 5 customers: 2 with town “New York”, and 5 with town “Madrid”.
I want the list to only hold only 2 customers. 1 with town “New York” and one with “Madrid”. If 2 are from “New York”, I want the last one. Same for “Madrid”.
What would the LINQ statement look like?
var newList = navigationList.GroupBy(c => c.Town) // ?
You would want something like
However, you would probably want to
OrderByfirst, so that theLastis meaningful:In this case the ordering is done by customer Id.