Implements a hashtable with the key strongly typed to be a string rather than an object.
public class StringDictionary: Object, IEnumerable
ObjectStringDictionary
// This sample shows how to implement the StringDictionary class. It also shows some methods and a property.
using System.Diagnostics;
using System.Collections;
using System.Collections.Specialized;
public class SampleStringDictionary
{
static void Main()
{
// Creates a new StringDictionary.
StringDictionary myStringDict = new StringDictionary();
// Adds the new entries to the HybridDictionary.
myStringDict.Add("first","Spring");
myStringDict.Add("second","Summer");
myStringDict.Add("third","Autumn");
myStringDict.Add("fourth","Winter");
// Displaying.
Debug.WriteLine("The StringDictionary:");
Debug.WriteLine("\tCount: " + myStringDict.Count);
Debug.WriteLine("\t" + "KEY \t\tVALUE"); DisplayStringDict(myStringDict
);
// Removes an entry from the StringDictionary.
myStringDict.Remove("fourth");
// Displaying.
Debug.WriteLine("\nThe StringDictionary after removing:");
Debug.WriteLine("\tCount: " + myStringDict.Count);
Debug.WriteLine("\t" + "KEY \t\tVALUE"); DisplayStringDict(myStringDict);
}
static void DisplayStringDict(StringDictionary myDict)
{
foreach (DictionaryEntry dicEntry in myDict)
Debug.WriteLine("\t" + dicEntry.Key + "\t\t" + dicEntry.Value);
}
}
/*
The output of the sample.
The StringDictionary:
Count: 4
KEY VALUE
fourth Winter
third Autumn
second Summer
first Spring
The StringDictionary after removing:
Count: 3
KEY VALUE
third Autumn
second Summer
first Spring
*/
Namespace System.Collections.Specialized Flash Library System.scl Flash Library Version 2.0.0.1308 Silverlight Library System.Windows.Forms.dll
| © 2003-2007 NETiKA Technologies. All rights reserved. |