OrderedDictionary Constructors

Definition

Initializes a new instance of the OrderedDictionary class.

Overloads

OrderedDictionary()

Initializes a new instance of the OrderedDictionary class.

OrderedDictionary(IEqualityComparer)

Initializes a new instance of the OrderedDictionary class using the specified comparer.

OrderedDictionary(Int32)

Initializes a new instance of the OrderedDictionary class using the specified initial capacity.

OrderedDictionary(Int32, IEqualityComparer)

Initializes a new instance of the OrderedDictionary class using the specified initial capacity and comparer.

OrderedDictionary(SerializationInfo, StreamingContext)
Obsolete.

Initializes a new instance of the OrderedDictionary class that is serializable using the specified SerializationInfo and StreamingContext objects.

OrderedDictionary()

Source:
OrderedDictionary.cs
Source:
OrderedDictionary.cs
Source:
OrderedDictionary.cs

Initializes a new instance of the OrderedDictionary class.

C#
public OrderedDictionary();

Examples

The following code example demonstrates the creation and population of an OrderedDictionary collection. This code is part of a larger code example that can be viewed at OrderedDictionary.

C#
// Creates and initializes a OrderedDictionary.
OrderedDictionary myOrderedDictionary = new OrderedDictionary();
myOrderedDictionary.Add("testKey1", "testValue1");
myOrderedDictionary.Add("testKey2", "testValue2");
myOrderedDictionary.Add("keyToDelete", "valueToDelete");
myOrderedDictionary.Add("testKey3", "testValue3");

ICollection keyCollection = myOrderedDictionary.Keys;
ICollection valueCollection = myOrderedDictionary.Values;

// Display the contents using the key and value collections
DisplayContents(keyCollection, valueCollection, myOrderedDictionary.Count);

Remarks

The comparer determines whether two keys are equal. Every key in a OrderedDictionary collection must be unique. The default comparer is the key's implementation of Object.Equals.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

OrderedDictionary(IEqualityComparer)

Source:
OrderedDictionary.cs
Source:
OrderedDictionary.cs
Source:
OrderedDictionary.cs

Initializes a new instance of the OrderedDictionary class using the specified comparer.

C#
public OrderedDictionary(System.Collections.IEqualityComparer comparer);
C#
public OrderedDictionary(System.Collections.IEqualityComparer? comparer);

Parameters

comparer
IEqualityComparer

The IComparer to use to determine whether two keys are equal.

-or-

null to use the default comparer, which is each key's implementation of Equals(Object).

Remarks

The comparer determines whether two keys are equal. Every key in a OrderedDictionary collection must be unique. The default comparer is the key's implementation of Object.Equals.

The custom comparer enables such scenarios as doing lookups with case-insensitive strings.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

OrderedDictionary(Int32)

Source:
OrderedDictionary.cs
Source:
OrderedDictionary.cs
Source:
OrderedDictionary.cs

Initializes a new instance of the OrderedDictionary class using the specified initial capacity.

C#
public OrderedDictionary(int capacity);

Parameters

capacity
Int32

The initial number of elements that the OrderedDictionary collection can contain.

Remarks

The comparer determines whether two keys are equal. Every key in a OrderedDictionary collection must be unique. The default comparer is the key's implementation of Object.Equals.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

OrderedDictionary(Int32, IEqualityComparer)

Source:
OrderedDictionary.cs
Source:
OrderedDictionary.cs
Source:
OrderedDictionary.cs

Initializes a new instance of the OrderedDictionary class using the specified initial capacity and comparer.

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

Parameters

capacity
Int32

The initial number of elements that the OrderedDictionary collection can contain.

comparer
IEqualityComparer

The IComparer to use to determine whether two keys are equal.

-or-

null to use the default comparer, which is each key's implementation of Equals(Object).

Remarks

The comparer determines whether two keys are equal. Every key in a OrderedDictionary collection must be unique. The default comparer is the key's implementation of Object.Equals.

The custom comparer enables such scenarios as doing lookups with case-insensitive strings.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

OrderedDictionary(SerializationInfo, StreamingContext)

Source:
OrderedDictionary.cs
Source:
OrderedDictionary.cs
Source:
OrderedDictionary.cs

Caution

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

Initializes a new instance of the OrderedDictionary class that is serializable using the specified SerializationInfo and StreamingContext objects.

C#
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected OrderedDictionary(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
C#
protected OrderedDictionary(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);

Parameters

info
SerializationInfo

A SerializationInfo object containing the information required to serialize the OrderedDictionary collection.

context
StreamingContext

A StreamingContext object containing the source and destination of the serialized stream associated with the OrderedDictionary.

Attributes

Remarks

The comparer determines whether two keys are equal. Every key in a OrderedDictionary collection must be unique. The default comparer is the key's implementation of Object.Equals.

Applies to

.NET 10 and other versions
Product Versions (Obsolete)
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7 (8, 9, 10)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1