.Net application development specialists
asp.net, c#, vb.net, html, javascript, jquery, html, xhtml, css, oop, design patterns, sql server, mvc and much more
contact: admin@paxium.co.uk

Paxium is the company owned by myself, Dave Amour and used for providing IT contract development services including


  • Application development - Desktop, Web, Services - with Classic ASP, Asp.net WebForms, Asp.net MVC, Asp.net Core
  • Html, Css, JavaScript, jQuery, React, C#, SQL Server, Ado.net, Entity Framework, NHibernate, TDD, WebApi, GIT, IIS
  • Database schema design, implementation & ETL activities
  • Website design and hosting including email hosting
  • Training - typically one to one sessions
  • Reverse Engineering and documentation of undocumented systems
  • Code Reviews
  • Performance Tuning
  • Located in Cannock, Staffordshire
Rugeley Chess Club Buying Butler Cuckooland Katmaid Pet Sitting Services Roland Garros 60 60 Golf cement Technical Conformity Goofy MaggieBears Vacc Track Find Your Smart Phone eBate Taylors Poultry Services Lafarge Rebates System Codemasters Grid Game eBate DOFF

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