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()

Initializes a new instance of the OrderedDictionary class.

public:
 OrderedDictionary();
public OrderedDictionary ();
Public Sub New ()

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.

// Creates and initializes a OrderedDictionary.
OrderedDictionary^ myOrderedDictionary = gcnew 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);
// 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);
' Creates and initializes a OrderedDictionary.
Dim myOrderedDictionary As New OrderedDictionary()
myOrderedDictionary.Add("testKey1", "testValue1")
myOrderedDictionary.Add("testKey2", "testValue2")
myOrderedDictionary.Add("keyToDelete", "valueToDelete")
myOrderedDictionary.Add("testKey3", "testValue3")

Dim keyCollection As ICollection = myOrderedDictionary.Keys
Dim valueCollection As ICollection = myOrderedDictionary.Values

' Display the contents Imports 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

OrderedDictionary(IEqualityComparer)

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

public:
 OrderedDictionary(System::Collections::IEqualityComparer ^ comparer);
public OrderedDictionary (System.Collections.IEqualityComparer comparer);
public OrderedDictionary (System.Collections.IEqualityComparer? comparer);
new System.Collections.Specialized.OrderedDictionary : System.Collections.IEqualityComparer -> System.Collections.Specialized.OrderedDictionary
Public Sub New (comparer As IEqualityComparer)

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

OrderedDictionary(Int32)

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

public:
 OrderedDictionary(int capacity);
public OrderedDictionary (int capacity);
new System.Collections.Specialized.OrderedDictionary : int -> System.Collections.Specialized.OrderedDictionary
Public Sub New (capacity As Integer)

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

OrderedDictionary(Int32, IEqualityComparer)

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

public:
 OrderedDictionary(int capacity, System::Collections::IEqualityComparer ^ comparer);
public OrderedDictionary (int capacity, System.Collections.IEqualityComparer comparer);
public OrderedDictionary (int capacity, System.Collections.IEqualityComparer? comparer);
new System.Collections.Specialized.OrderedDictionary : int * System.Collections.IEqualityComparer -> System.Collections.Specialized.OrderedDictionary
Public Sub New (capacity As Integer, comparer As IEqualityComparer)

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

OrderedDictionary(SerializationInfo, StreamingContext)

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.

protected:
 OrderedDictionary(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected OrderedDictionary (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
[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);
new System.Collections.Specialized.OrderedDictionary : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Collections.Specialized.OrderedDictionary
[<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}")>]
new System.Collections.Specialized.OrderedDictionary : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Collections.Specialized.OrderedDictionary
Protected Sub New (info As SerializationInfo, context As StreamingContext)

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