Remove duplicates from a List<T> in C#

JC Grubbs picture JC Grubbs · Sep 6, 2008 · Viewed 612.2k times · Source

Anyone have a quick method for de-duplicating a generic List in C#?

Answer

Factor Mystic picture Factor Mystic · Sep 6, 2008

If you're using .Net 3+, you can use Linq.

List<T> withDupes = LoadSomeData();
List<T> noDupes = withDupes.Distinct().ToList();