example array:
int[] s new = {1,2,3,1};
if use:
int[] inew = snew.Distinct().ToArray();
then out put:
{1,2,3}
but I want out put:
{2,3}
Gilad Green
37.3k7 gold badges67 silver badges99 bronze badges
asked Jul 25, 2017 at 16:38
1 Answer 1
You need to select everything where duplicate count is == 1:
snew.GroupBy(x => x)
.Where(x => x.Count() == 1)
.Select(x => x.First())
.ToArray();
Fiddle here
answered Jul 25, 2017 at 16:39
Sign up to request clarification or add additional context in comments.
3 Comments
Thomas Weller
Ahh, slowly you're coming to a solution... FGITW, hmm?
Artem
Group is much cleaner than your initial answer :)
maccettura
@ThomasWeller yeah sorry, I was going by memory then slowly changing my answer every time I realized my mistakes haha. Then I just went on dotnetfiddle and figured out the right syntax.
lang-cs