0

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

3

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

Ahh, slowly you're coming to a solution... FGITW, hmm?
Group is much cleaner than your initial answer :)
@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.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.