OrderedDictionary<TKey,TValue> Constructors

Definition

Overloads

OrderedDictionary<TKey,TValue>()

Initializes a new instance of the OrderedDictionary<TKey,TValue> class that is empty,

has the default initial capacity, and uses the default equality comparer for the key type.

OrderedDictionary<TKey,TValue>(IDictionary<TKey,TValue>)

Initializes a new instance of the OrderedDictionary<TKey,TValue> class that contains elements copied from

the specified IDictionary<TKey,TValue> and uses the default equality comparer for the key type.

OrderedDictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>)

Initializes a new instance of the OrderedDictionary<TKey,TValue> class that contains elements copied

from the specified IEnumerable<T> and uses the default equality comparer for the key type.

OrderedDictionary<TKey,TValue>(IEqualityComparer<TKey>)

Initializes a new instance of the OrderedDictionary<TKey,TValue> class that is empty,

has the default initial capacity, and uses the specified IEqualityComparer<T>.

OrderedDictionary<TKey,TValue>(Int32)

Initializes a new instance of the OrderedDictionary<TKey,TValue> class that is empty,

has the specified initial capacity, and uses the default equality comparer for the key type.

OrderedDictionary<TKey,TValue>(IDictionary<TKey,TValue>, IEqualityComparer<TKey>)

Initializes a new instance of the OrderedDictionary<TKey,TValue> class that contains elements copied from

the specified IDictionary<TKey,TValue> and uses the specified IEqualityComparer<T>.

OrderedDictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>, IEqualityComparer<TKey>)

Initializes a new instance of the OrderedDictionary<TKey,TValue> class that contains elements copied

from the specified IEnumerable<T> and uses the specified IEqualityComparer<T>.

OrderedDictionary<TKey,TValue>(Int32, IEqualityComparer<TKey>)

Initializes a new instance of the OrderedDictionary<TKey,TValue> class that is empty,

has the specified initial capacity, and uses the specified IEqualityComparer<T>.

OrderedDictionary<TKey,TValue>()

Initializes a new instance of the OrderedDictionary<TKey,TValue> class that is empty,

has the default initial capacity, and uses the default equality comparer for the key type.

C#
public OrderedDictionary();

Applies to

.NET 10 and .NET 9
Product Versions
.NET 9, 10

OrderedDictionary<TKey,TValue>(IDictionary<TKey,TValue>)

Initializes a new instance of the OrderedDictionary<TKey,TValue> class that contains elements copied from

the specified IDictionary<TKey,TValue> and uses the default equality comparer for the key type.

C#
public OrderedDictionary(System.Collections.Generic.IDictionary<TKey,TValue> dictionary);

Parameters

dictionary
IDictionary<TKey,TValue>

The IDictionary<TKey,TValue> whose elements are copied to the new OrderedDictionary<TKey,TValue>.

The initial order of the elements in the new collection is the order the elements are enumerated from the supplied dictionary.

Exceptions

dictionary is null.

Applies to

.NET 10 and .NET 9
Product Versions
.NET 9, 10

OrderedDictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>)

Initializes a new instance of the OrderedDictionary<TKey,TValue> class that contains elements copied

from the specified IEnumerable<T> and uses the default equality comparer for the key type.

C#
public OrderedDictionary(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey,TValue>> collection);

Parameters

collection
IEnumerable<KeyValuePair<TKey,TValue>>

The IEnumerable<T> whose elements are copied to the new OrderedDictionary<TKey,TValue>.

The initial order of the elements in the new collection is the order the elements are enumerated from the supplied collection.

Exceptions

collection is null.

Applies to

.NET 10 and .NET 9
Product Versions
.NET 9, 10

OrderedDictionary<TKey,TValue>(IEqualityComparer<TKey>)

Initializes a new instance of the OrderedDictionary<TKey,TValue> class that is empty,

has the default initial capacity, and uses the specified IEqualityComparer<T>.

C#
public OrderedDictionary(System.Collections.Generic.IEqualityComparer<TKey>? comparer);

Parameters

comparer
IEqualityComparer<TKey>

The IEqualityComparer<T> implementation to use when comparing keys,

or null to use the default EqualityComparer<T> for the type of the key.

Applies to

.NET 10 and .NET 9
Product Versions
.NET 9, 10

OrderedDictionary<TKey,TValue>(Int32)

Initializes a new instance of the OrderedDictionary<TKey,TValue> class that is empty,

has the specified initial capacity, and uses the default equality comparer for the key type.

C#
public OrderedDictionary(int capacity);

Parameters

capacity
Int32

The initial number of elements that the OrderedDictionary<TKey,TValue> can contain.

Exceptions

capacity is less than 0.

Applies to

.NET 10 and .NET 9
Product Versions
.NET 9, 10

OrderedDictionary<TKey,TValue>(IDictionary<TKey,TValue>, IEqualityComparer<TKey>)

Initializes a new instance of the OrderedDictionary<TKey,TValue> class that contains elements copied from

the specified IDictionary<TKey,TValue> and uses the specified IEqualityComparer<T>.

C#
public OrderedDictionary(System.Collections.Generic.IDictionary<TKey,TValue> dictionary, System.Collections.Generic.IEqualityComparer<TKey>? comparer);

Parameters

dictionary
IDictionary<TKey,TValue>

The IDictionary<TKey,TValue> whose elements are copied to the new OrderedDictionary<TKey,TValue>.

The initial order of the elements in the new collection is the order the elements are enumerated from the supplied dictionary.

comparer
IEqualityComparer<TKey>

The IEqualityComparer<T> implementation to use when comparing keys,

or null to use the default EqualityComparer<T> for the type of the key.

Exceptions

dictionary is null.

Applies to

.NET 10 and .NET 9
Product Versions
.NET 9, 10

OrderedDictionary<TKey,TValue>(IEnumerable<KeyValuePair<TKey,TValue>>, IEqualityComparer<TKey>)

Initializes a new instance of the OrderedDictionary<TKey,TValue> class that contains elements copied

from the specified IEnumerable<T> and uses the specified IEqualityComparer<T>.

C#
public OrderedDictionary(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey,TValue>> collection, System.Collections.Generic.IEqualityComparer<TKey>? comparer);

Parameters

collection
IEnumerable<KeyValuePair<TKey,TValue>>

The IEnumerable<T> whose elements are copied to the new OrderedDictionary<TKey,TValue>.

The initial order of the elements in the new collection is the order the elements are enumerated from the supplied collection.

comparer
IEqualityComparer<TKey>

The IEqualityComparer<T> implementation to use when comparing keys,

or null to use the default EqualityComparer<T> for the type of the key.

Exceptions

collection is null.

Applies to

.NET 10 and .NET 9
Product Versions
.NET 9, 10

OrderedDictionary<TKey,TValue>(Int32, IEqualityComparer<TKey>)

Initializes a new instance of the OrderedDictionary<TKey,TValue> class that is empty,

has the specified initial capacity, and uses the specified IEqualityComparer<T>.

C#
public OrderedDictionary(int capacity, System.Collections.Generic.IEqualityComparer<TKey>? comparer);

Parameters

capacity
Int32

The initial number of elements that the OrderedDictionary<TKey,TValue> can contain.

comparer
IEqualityComparer<TKey>

The IEqualityComparer<T> implementation to use when comparing keys,

or null to use the default EqualityComparer<T> for the type of the key.

Exceptions

capacity is less than 0.

Applies to

.NET 10 and .NET 9
Product Versions
.NET 9, 10