Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
 HashSet and LINQ Set Operations

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Developer's Guide
HashSet and LINQ Set Operations

This topic compares HashSet<(Of <(T>)>) operations and Language-Integrated Query (LINQ) set operations.

LINQ provides access to some set operations to any data source that implements the IEnumerable or IQueryable interfaces. This includes arrays and collections.

The set operations that LINQ provides are as follows:

  • Distinct

  • Union

  • Intersect

  • Except

For more information about LINQ, see Language-Integrated Query (LINQ). For more information about LINQ set operations, see Set Operations.

The primary difference between LINQ set operations and HashSet<(Of <(T>)>) operations is that the LINQ set operations always return a new IEnumerable<(Of <(T>)>) collection, while the HashSet<(Of <(T>)>) equivalent methods modify the current collection. HashSet<(Of <(T>)>) provides a larger and more robust collection of set operations. For example, HashSet<(Of <(T>)>) provides comparisons such as IsSubsetOf and IsSupersetOf.

Typically, if you must create a new set or if your application needs access only to the provided set operations, using LINQ set operations on any IEnumerable<(Of <(T>)>) collection or array will be sufficient. However, if your application requires access to additional set operations, or if it is not desirable or necessary to create a new collection, use the HashSet<(Of <(T>)>) class.

The following table shows the HashSet<(Of <(T>)>) operations and their equivalent LINQ set operations.

HashSet(Of T) operation

LINQ equivalent

UnionWith

Union

IntersectWith

Intersect

ExceptWith

Except

Not Provided

Distinct

SymmetricExceptWith

Not Provided.

Overlaps

Not Provided.

IsSubsetOf

Not Provided.

IsProperSubsetOf

Not Provided.

IsSupersetOf

Not Provided.

IsProperSupersetOf

Not Provided.

SetEquals

Not Provided.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker