Reputation: 21
Is it possible to remove all non unique values in list structure? If List contains these values
11,9,8,7,6,5,4,10,8,7,6,5,4,2
.
But after removing duplicates it should be
11,9,10,2
.
If I try to divide this list on half and than apply List.Concat(List2).Disticnt()
values 8,7,6,5,4
are still in the List.
Upvotes: 2
Views: 89
Reputation: 32576
var list = new List<int>() { 11, 9, 8, 7, 6, 5, 4, 10, 8, 7, 6, 5, 4, 2 };
var list2 = list.GroupBy(x => x)
.Where(x => x.Count() == 1)
.Select(x => x.First())
.ToList();
Upvotes: 6