Kornwit Pumphis Kornwit Pumphis - 3 years ago 105
C# Question

Remove all value duplicates in array

example array:
int[] snew = {1,2,3,1};

if use:
int[] inew = snew.Distinct().ToArray();

then out put:
{1,2,3}

but i want out put:
{2,3}

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download