C# unique values from list (removing dupes entirely)


How to achieve the following?

Input List: A,A,B,B,B,C,D,E,E,F

Expected Output List: C,D,F

>Solution :

You could use group by and take only groups with exactly one element:

var input = new string[] {"A","A","B","B","B","C","D","E","E","F"};
var result = input.GroupBy(x => x).Where(x => x.Count() == 1).Select(x => x.Key).ToList();

Online-demo: https://dotnetfiddle.net/j2vraK

Leave a Reply Cancel reply