Hi CD,
Hmm...
If by "a good example of implementing a Dictionary" you mean *using* an
existing dictionary class, then the Hashtable class implements the
IDictionary interface, and can be used as a dictionary.
Create a C# console application, and paste this code into/over the Main
method call:
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Hashtable h = new Hashtable();
h.Add(@"001", @"One");
h.Add(@"002", @"Two");
h.Add(@"003", @"Three");
h.Add(@"004", @"Four");
// Access values via keys
Console.WriteLine(@"ONE = {0}", h[@"001"]);
Console.WriteLine(@"THREE = {0}", h[@"003"]);
Console.ReadLine();
}
Hope this helps...
regards
Patrick
"CD" wrote:
Hi,
I'm trying to learn C#. I'm coming from Smalltalk. I need a good example of
implementing a Dictionary (Keys->values) without having to create my own
subclass.
I see how to add, but not sure how to create and instance, how to access the
value for one key
thanks