Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

HashSet<T> Constructor (IEnumerable<T>^)

 

Initializes a new instance of the HashSet<T> class that uses the default equality comparer for the set type, contains elements copied from the specified collection, and has sufficient capacity to accommodate the number of elements copied.

Namespace:   System.Collections.Generic
Assembly:  System.Core (in System.Core.dll)

public:
HashSet(
	IEnumerable<T>^ collection
)

Parameters

collection
Type: System.Collections.Generic::IEnumerable<T>^

The collection whose elements are copied to the new set.

Exception Condition
ArgumentNullException

collection is null.

The capacity of a HashSet<T> object is the number of elements that the object can hold. A HashSet<T> object's capacity automatically increases as elements are added to the object.

If collection contains duplicates, the set will contain one of each unique element. No exception will be thrown. Therefore, the size of the resulting set is not identical to the size of collection.

This constructor is an O(n) operation, where n is the number of elements in the collection parameter.

The following example shows how to create a HashSet<T> collection from an existing set. In this example, two sets are created with even and odd integers, respectively. A third HashSet<T> object is then created from the even integer set.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 4.0
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2017 Microsoft