.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 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