lomaxx lomaxx - 2 years ago 184
C# Question

Remove duplicates from array

I have been working with a

array in C# that gets returned from a function call. I was wondering what the best way to remove duplicates from this array would be? I could possibly cast to a Generic collection, but I was wondering if there was a better way to do it, possibly by using a temp array?

Answer Source

You could possibly use a LINQ query to do this:

int[] s = { 1, 2, 3, 3, 4};
int[] q = s.Distinct().ToArray();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download