Mid Collections

How do you check if a List<T> contains a duplicate element?

Use GroupBy, Distinct, or nested loops.

Follow:

Example:

bool hasDuplicates = list.Count != list.Distinct().Count();

More from C# Programming Tutorial

All questions for this course