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 ListDictionary

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

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

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

This class implements IDictionary using a singly linked list. Recommended for collections that typically contain 10 items or less.

I cannot see anything at the interface end which is linked list like so looks like the linked list usage is just under the hood so not sure what the point of that is?

It can be found at System.Collections.Specialized.ListDictionary

It contains key value pairs which are in the form of DictionaryEntry objects and items are retrievable via iteration or via key.

Below is a sample program showing the typical usage of this class.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.Collections;
 
namespace ListDictionaryExamples
{
    class Program
    {
        static void Main(string[] args)
        {
            ListDictionary drinks = new ListDictionary();
 
            drinks.Add("Lager", 1.98);
            drinks.Add("Guiness", 2.11);
            drinks.Add("Bitter", 2.05);
            drinks.Add("Red Wine", 2.45);
            drinks.Add("White Wine", 2.35);
 
            Console.WriteLine("Output drink contents using foreach");
           
            foreach (DictionaryEntry drink in drinks)
            {
                Console.WriteLine(drink.Key + " " + drink.Value);
            }
 
            Console.WriteLine();
           
            IDictionaryEnumerator drinksEnumerator = drinks.GetEnumerator();
 
            Console.WriteLine("Output drink contents using enumerator");
 
            while (drinksEnumerator.MoveNext())
            {
                Console.WriteLine(drinksEnumerator.Key + " " + drinksEnumerator.Value);
            }
 
            Console.WriteLine();
 
            Console.WriteLine(drinks["Bitter"]);
 
            Console.Read();
        }
    }
}


The output from this program is as follows:

Thats as much as there is to the ListDictionary.

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

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