Author - Dave Amour

Dave Amour has used computers for as long as he can remember and intially started out as an IT trainer delivering a range of IT courses but for the last 11 years has been focusing on the arena of web application development. He was worked for numerous companies over the years and is currently working for Audacs Software Ltd. Dave is also a keen squash player and an active and sucessful member of Experts Exchange

Please feel free to submit any constructive comments which you can do at the bottom of this page.

Dave may be available for programming tuition or consultancy work. Contact via dave@audacs.co.uk
Dave Amour - Click to view CV 

Collection Classes in .net - the StringDictionary

This is the eleventh part of an article on collection classes in .net with C#.  This part covers the StringDictionary.

For the first part see http://www.audacs.co.uk/ViewPage.aspx?PageID=512

For the next part on the HybridDictionary see http://www.audacs.co.uk/ViewPage.aspx?PageID=525

This appears to be just a regular hashtable but strongly typed to work with strings rather than objects.  It must therefore be pre generics.

Most people seem to be of the oppinion that we should now use the generic dictionary where possible and only use this for legacy code.

For legacy and historical purposes though we will have a quick code exmample.

The class can be found at:

System.Collections.Specialized.StringDictionary

And here is a sample program and output:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
 
namespace StringDictionaryExamples
{
    class Program
    {
        static void Main(string[] args)
        {
            StringDictionary states = new StringDictionary();
 
            states.Add("WA", "WASHINGTON");
            states.Add("AL", "ALABAMA");
            states.Add("CO", "COLORADO");
            states.Add("HI", "HAWAII");
            states.Add("MT", "MONTANA");
            states.Add("NY", "NEWYORK");
 
            foreach (System.Collections.DictionaryEntry state in states)
            {
                Console.WriteLine(state.Key + " " + state.Value);
            }
 
            Console.WriteLine();
 
            Console.WriteLine("The state of NY is " + states["NY"]);
 
            Console.Read();
        }
    }
}


 

You will probably have noticed that the keys have been changed to lower case. This is by design even though it could obviously catch you out or cause problems.

See this thread for more info on this.

http://haacked.com/archive/2004/06/25/685.aspx

So thats about it for the StringDictionary.

For the next part on the HybridDictionary see http://www.audacs.co.uk/ViewPage.aspx?PageID=525

Leave a comment

Name

Email (optional and not disclosed)



Email address is not disclosed but just used to alert you of new posts if entered
Word CV
HTML CV
PDF CV
Text CV
CMS Lite
ETraining
Planet Health
Florida Health
the Date Shack
Taylors
Emcat
Emtex
Browne Jacobson
Alliance & Leicester
Baird Leisure
Swarfega
Creature Comforts
Rugeley Chess Club
Katnip
Katmaid
Dudley NHS
Contact Me
Current Status