Dictionary Class (BCL)

Use this object to support the creation, storage, and retrieval of name/value pairs in memory. Every value in a Dictionary object is an Object, which means you can create a Dictionary object that consists of almost any kind of value (including other Dictionary objects), and that you can store any combination of Object types in the same Dictionary object.

Public Instance Methods

Method Description
GetEnumerator Returns an enumerator for Dictionary objects

Public Instance Properties

Property Type Description
Count Integer Returns the number of elements in the Dictionary object.

This property is read-only.

Prefix String Stores the string that acts as a filter when the contents of the Dictionary object are saved (usually to a database). When the name of a name/value pair begins with the specified prefix, that name/value pair is not saved.

This property is read/write.

Value Object Stores the value of a given Dictionary key.

This property is read/write.

Remarks

[Visual Basic .NET]

Because a Dictionary object is designed to be a general-purpose collection, you can use it for almost anything that its internal structure supports.

Dim dictUser As Dictionary

After instantiating the object, you can add elements to it, as follows:

dictUser.Value( “firstName” ) = "Steve"

In this example, first_name is a Dictionary key, and Steve becomes the assigned value of this key. Each statement actually accomplishes three functions: declaring the Dictionary key, adding that key to the Dictionary object, and setting the key to a value.

You can use the Value method to get the value of a given key:

my_first_name = dictUser.Value("first_name")

You can also use the For Each statement in Microsoft Visual Basic Scripting Edition (VBScript) to enumerate through the keys or the values of a Dictionary object as follows (this example assumes that every value in the dictionary contains text):

' // Get the key names and values

For Each element In dictUser

Console.WriteLine(“name = {0}; value = {1}”, element, dictUser[element]);

        Next

The data in a Dictionary object can be saved in a database table by using the DBStorage object.

Commerce Server 2002 sites use implementations of the Dictionary object to store sets of data that are required by various other objects and pipeline components.

Unlike previous versions of the dictionary, the dictionary in Commerce Server 2002 is implemented as a hash of name value pairs. This enables the dictionary to perform fast lookups even when a large number of key/value pairs are stored. It also has the side effect that enumerations of dictionary keys may not be returned in the same order they are stored.

The Dictionary object supports the ICloneable and IPersistXML interfaces. Use the ICloneable interface to deep copy all name/value pairs into a new dictionary. Use the IPersistXML interface to convert the Dictionary entries into an XML string and back again.

[C#]

Because a Dictionary object is designed to be a general-purpose collection, you can use it for almost anything that its internal structure supports.

When you need to create a Dictionary object explicitly (that is, when the object is not created for you by some other Commerce Server 2002 object), use the standard creation with new as follows:

using Microsoft.CommerceServer.Interop;
…
Dictionary dictUser = new Dictionary();

After creating the object, you can add elements to it, as follows:

dictUser[“firstName”] = "Steve";

In this example, “firstName” is a Dictionary key, and “Steve” becomes the assigned value of this key. Each statement actually accomplishes three functions: declaring the Dictionary key, adding that key to the Dictionary object, and setting the key to a value.

You can extract values from a Dictionary object in several ways. You can simply place the object.key identifier on the right side of the assignment statement. Such an assignment returns the value of the referenced key:

using Microsoft.CommerceServer.Interop;
Commerce.IDictionary dictUser = new Dictionary();
dictUser["key1"] = "value1";
string s = dictUser["key1"].ToString();

You can also use the foreach statement in Microsoft C# to enumerate through the keys or the values of a Dictionary object as follows (this example assumes that every value in the dictionary contains text):

// Get the key names and values
foreach ( string name in dictUser )
    Console.WriteLine(“name = {0}; value = {1}”, name, dictUser[name]);

The data in a Dictionary object can be saved in a database table by using the Microsoft.CommerceServer.Interop.Orders.DBStorage object.

Commerce Server 2002 sites use implementations of the Dictionary object to store sets of data that are required by various other objects and pipeline components.

Unlike previous versions of the dictionary, the dictionary in Commerce Server 2002 is implemented as a hash of name value pairs. This enables the dictionary to perform fast lookups even when a large number of key/value pairs are stored. It also has the side effect that enumerations of dictionary keys may not be returned in the same order they are stored.

The Dictionary object supports the ICloneable and IPersistXML interfaces. Use the ICloneable interface to deep copy all name/value pairs into a new dictionary. Use the IPersistXML interface to convert the Dictionary entries into an XML string and back again.

Requirements

Namespace: Microsoft.CommerceServer.Runtime

Platforms: Windows 2000, Windows Server 2003

Assembly: mscscorelib (in mscscorelib.dll)

See Also

Core Objects

IPersistXML Interface

SimpleList Class

Copyright © 2005 Microsoft Corporation.
All rights reserved.