How I remove duplicates from something that implements IEnumerable<T>

by Mikael Henriksson 5. June 2010 18:32

I admit it does not work for everything and only in C# 4 but it’s a useful extension none the less.

public static IEnumerable<T> RemoveDuplicates<T>(this IEnumerable<T> items)
{
	return new HashSet<T>(items);
}

The hash set does not allow duplicates!

Tags: ,

LINQ | C#

blog comments powered by Disqus

About the author

Life architect specialized in programming