How to delete duplicate values in an array?

c#

Solution

With LINQ it's easy:

var intArray = new[] { 2000, 2011, 2011, 2012, 2009, 2009, 2000 };
var uniqueArray = intArray.Distinct().ToArray();

http://msdn.microsoft.com/en-us/library/system.linq.enumerable.distinct.aspx

Another way is using Enumerable.GroupBy:

uniqueArray = intArray.GroupBy(i => i).Select(grp => grp.Key).ToArray();

Problem

Possible Duplicate: Remove duplicates from array I have an int array which contains a defined number of elements, all positive. I want to get an array from this one where all the elements appear only once. e.g. If the first array was something like `{2000,2011,2011,2012,2009,2009,2000}`, I want to get this `{2000,2011,2012,2009}`. How can I do this? I tried lots of things with for loops but I can't manage to do something good.

Original source

Related problems