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 StringCollection

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

The StringCollection class can be found at System.Collections.Specialized.StringCollection

In essence this is just a strongly typed ArrayList.  It works just like an ArrayList but holds only strings.  We therefore get performance benefits since there is no casting.  We also get compile time type checking and type safety - just like we do with generics.  And in fact this begs the question as to whether this class is now obsolete since we now have generics?  Any offers on this question - use the form below.

Of course even if this is obsolete, it does still need to be kept for legacy code - it's just a question of whether we use it for new code or not.  I would say not.

See the comments at the end of http://msdn.microsoft.com/en-us/library/system.collections.specialized.stringcollection(VS.80).aspx

Ok not much else to say on StringCollection other than here is a simple code example.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
 
namespace StringCollections
{
    class Program
    {
        static void Main(string[] args)
        {
            StringCollection colours = new StringCollection();
 
            colours.Add("Red");
            colours.Add("Green");
            colours.Add("Blue");
            colours.Add("Yellow");
            colours.Add("Orange");
 
            foreach (string colour in colours)
            {
                Console.WriteLine(colour);
            }
 
            Console.Read();
        }
    }
}


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

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

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