Mid LINQ

How to perform union of two collections without duplicates?

How to perform union of two collections without duplicates?

var list1 = new[] { "Alice", "Bob", "Charlie" };

var list2 = new[] { "Bob", "David", "Eva" };

var union = list1.Union(list2);

foreach (var name in union)

Console.WriteLine(name);

Explanation:

Union returns distinct elements from both collections.

More from LINQ Tutorial

All questions for this course