C Sharp List and ArrayList Collections
In the previous chapter we looked at C# Arrays. Whilst useful for many tasks arrays are really starting to show their age in terms of both functionality and flexibility. More advanced mechanisms for gathering groups of objects are provided by the C# Collection Classes.
What are C# Collection Classes
The C# Collection classes are a set of classes designed specifically for grouping together objects and performing tasks on them. A number of collection classes are available with C# and we will be looking at the key classes in this chapter.
C# List Collections - List<T> and ArrayList
Both the List<T> and ArrayList classes have properties very similar to C# arrays (for details on arrays refer to Introducing C# Arrays. One key advantage of these classes over arrays is that they can grow and shrink as the number of stored objects changes.
The List<T> class is contained with the System.Collections.Generic namespace whilst the ArrayList class is contained within the System.Collections namespace.
The syntax for creating a List<T> collection is as follows:
List<type> name = new List<type>();