Kornwit Pumphis
Kornwit Pumphis

Reputation: 3

Remove all value duplicates in array

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}

Upvotes: 0

Views: 49

Answers (1)

maccettura
maccettura

Reputation: 10818

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

Upvotes: 3

Related Questions