Method or Property
Description
Remove()
Removes the specified item (key or key/value pair) from the dictio-
nary. This method must be overridden.
RemoveMany()
Accepts an
IEnumerable<T>
collection of items to be removed,
searches for matching keys, and removes each item for which a match
can be found. I
Replace()
Finds the item that matches the supplied key and replaces its value
with the supplied value.
Reversed()
Retrieves an
OrderedDictionary<T>.View
collection that contains
all the items in the dictionary sorted in reverse order.
TryGetValue()
Attempts to get the value associated with the supplied key. This
method must be overridden.
An
OrderedDictionary<TKey, TValue>
class holds a set of unique keys, each of which has an associ-
ated value. As such, all random access methods will use keys to find, update, and remove items from the
dictionary. The following example performs some basic operations on this class so you can get a better
feeling for what options you can use to maintain the contents of a dictionary:
[VB code]
Dim strDict As New OrderedDictionary(Of String, String)
strDict.Add("932", "Item7")
strDict.Add("111", "Item2")
strDict.Add("82", "Item9")
strDict.Add("32", "Item4")
strDict.Add("20", "Item5")
DumpItems(Of String, String)(strDict)
Dim aStr As String = strDict("82")
Console.WriteLine("First Item : {0}", aStr)
Dim tmpItem As String = "Item22"
Dim itemFound As Boolean = strDict.GetValueElseAdd("9329", tmpItem)
If (itemFound = False) Then
Console.WriteLine("Key Not Found--item added")
End If
[C# code]
OrderedDictionary<String, String> strDict = new OrderedDictionary<String,String>();
strDict.Add("932", "Item7");
strDict.Add("111", "Item2");
strDict.Add("82", "Item9");
strDict.Add("32", "Item4");
strDict.Add("20", "Item5");
DumpItems<String, String>(strDict);
String aStr = strDict["82"];
Console.WriteLine("First Item : {0}", aStr);
351
Power Collections
17_559885 ch14.qxd 9/8/05 11:07 PM Page 351