Collections
Collections can be very useful and can also be used for data binding.
A collection class is used to group objects together.
There are a number of different types of collection classes.
An array is just a special type of collection class.
Some of these collections can hold any type of object whereas others are strongly typed.
Collection classes provide members to add, remove, find and retrieve items
Collection classes also expand automatically when more items are added.
Different Types of Collections
There are two different types of collections
Standard (or generalized) - (ArrayList, BitArray, Hashtable, Queue, SortedList, Stack)
Generic (or specialized) - (Dictionary, HashSet, LinkedList, List Queue, SortedSet, SortedDictionary, SortedList, Stack)
Standard Collections
Added in .NET 1.1
These are the main collection classes and can all be found in the System.Collections namespace
Generic Collections
Added in .NET 2.0
You should always try and program against an interface and not a class implementation
When the class is instantiated the type must be specified
Makes it easier to create type safe collections
These are special versions that allow you to create strongly typed collections.
Collection Initializers
Added in .NET 3.5
This provides a shortened syntax that enables you to create a collection and populate it with an initial set of values
var myChildren = new List<Person>
{
new Person { Name = "Lisa"; }
new Person { Name = "Richard"; }
}
List<int> mylist = new List<int> {0,1,2,3,4,5};
This was added to VB.Net in Visual Studio 2010.
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopNext