Set Operators

Set operators let you remove duplicates and merge sequences and exclude specified elements. For instance, 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:

Dim someInt = {1, 2, 3, 3, 2, 4}'Returns {1, 2, 3, 4}Dim result = From number In someInt Distinct            Select number

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, excluding ...

Get Visual Basic 2015 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.