C# – Remove duplicates from a List in C#

cduplicatesgenericslist

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

Best Answer

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

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