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.


Which Collection to Use ?

Unique list of IDs - ArrayList (basically a dynamic single dimensional array)
Individual items selected - ArrayList



Different Types of Collections

There are two different types of collections

  • Standard (or generalized) - (ArrayList, HashTable, SortedList, Queue, Stock)



  • Generic (or specialized) - (Lists)

These were added in .NET 2.0
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.


Standard

These are the main collection classes and can all be found in the System.Collections namespace


Array 
ArrayListThis can work with any type of data (objects, strutcs or primitive types)
Doesn't have a (key,value) relationship
BitArray 
CaseInsensitiveComparer 
CaseInsensitiveHashCodeProvider 
CollectionBase 
Comparer 
DictionaryBase 
DictionaryEntry 
HashTable 
ICollectionimplemented by all collections
IComparercompares two objects, used for sorting
IDictionaryfor key/value based collections
IEnumerabledesignates a class that can be enumerated
IEnumeratordesignates a class that iterates over a collection, supports for each loops
IEqualityComparer 
IHashCodeProvider 
IListused by collections that can be indexed
QueueFirst in, first out collection
ReadOnlyCollectionBase 
SortedList 
StackLast in, first out collection


Generic Collections

You should always try and program against an interface and not a class implementation



Collection Class

VB.NET offers a generic collection class namely Collection.
The ArrayList and Collection classes are very similar.
The Collection class however overloads the Item property to take a string as a key into the collection.
This allows the Collection class to act as a dictionary, associating keys with values.
You can also use the Item property to access members of the collection by index value, however the Collection uses a 1-based index rather than 0-based.



© 2017 Better Solutions Limited. All Rights Reserved. © 2017 Better Solutions Limited

Top

Next