6.14. Compare and Combine Collections

Problem

You need to quickly compare or combine the contents of two collections.

Solution

Call the Except, Intersect, or Union method to perform the appropriate action. If you need to combine the data, use the Concat method.

How It Works

Most of the functionality supported by LINQ is directly related to building queries. The System. Linq.Enumerable class, which is where the extension methods used by LINQ are located, contains additional supporting methods. Although these methods don't have query clauses directly associated with them, they can still be used with queries since they return objects that inherit IEnumerable(Of T).

Four examples of these methods are Except, Intersect, Union, and Concat. Except, ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.