Gunnar Peipman's ASP.NET blog

ASP.NET, C#, SharePoint, SQL Server and general software development topics.






Getting distinct values from arrays (through .NET Framework history)

Getting distinct values from arrays is not a unique problem. Here will I show some options how to do it. We are will use array of integer in examples here. This blog entry shows you somehow the mighty evolution of .Net Framework.


NB! This blog is moved to

Click here to go to article


Guy said:

Nice, interesting post, and a good application of a generic method in the .NET 2.0 section.

# May 15, 2008 10:28 AM

Jon von Gillern said:

Word of warning: If you have more than a couple hundred elements in your array, you'd be much better off doing a quick sort on your list then doing a single pass through the array and only add to the distinct list when the element is not the same as the previous element. Depending on your memory requirements, you could also use a dictionary (or the new HashSet) to keep track of what has already been added. If I remember correctly this later method is what LINQ's Distinct keyword does.

# May 16, 2008 9:20 AM

DigiMortal said:

Yes, that's correct - you should sort larger arrays before asking distinct values because checking operations work faster when input array is sorted.

# May 18, 2008 10:40 AM

kanchana said:

Nice, simply superb to understand ...

# May 23, 2008 10:16 AM

dedisianturi said:

Is there an algorithm to distinct value in array?


# November 4, 2009 2:33 AM

DigiMortal said:

Use Ling to get distinct values. Just add reference to System.Linq namespace and your arrays get a lot of extension methods you can use. ust go to array and open IntelliSense to see what is there for you.

# November 4, 2009 5:25 AM

sayed said:

very helpullllll........and nice article.


# December 27, 2010 6:26 AM

Sean said:

Very helpful article! Thanks

# October 12, 2011 12:04 PM

Ajay said:

very helpful as it shown the progress from version to version.. elaboratively explained...

# June 7, 2012 11:03 AM