Set Operators

Set operators allow removing duplicates and merge sequences and exclude specified elements. For example you could have duplicate items within a sequence or collection; you can remove duplicates using the Distinct operator. The following provides an example on a simple array of integers:

image

The result is a new IEnumberable(Of Integer). In real scenarios you could find this operator useful in LINQ to SQL or the Entity Framework for searching duplicate records in a database table. The next operator is Union, which is an extension method and merges two sequences into a new one. The following is an example:

The preceding code returns an ...

Get Visual Basic® 2010 Unleashed 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.