Sunday, 2 October 2011

Types of Collections in .NET


There are many types of collections in the .Net Framework 2.0. The most general types of them are under the "System.Collections" namespace. All of them have the following basic methods and properties to manipulate the stored data. "Add" to add a new element, "Remove" to remove an existing element, and "Count" to get the total number of elements stored in a collection.
Non-Generic Collections
Found under the "System.Collections" namespace.
ArrayList: an array of contiguous indexed elements whose size can be increased dynamically at run time as required. You can use this data structure to store any types of data like integers, strings, structures, objects, .....
BitArray: an array of contiguous bit values (zeros and ones). Its size must be determined at design time.
SortedList: represents a list of key/value pair elements, sorted by keys and can be accessed by key and by index.
Stack: represents the data structure of last-in-first-out (LIFO).
Queue: represents the data structure of first-in-first-out (FIFO).
HashTable: represents a collection of key/value pair elements stored based on the hash code of the key.

Generic Collections
Found under the "System.Collections.Generic" namespace.
LinkedList: represents a doubly linked list data structure of a specified data type.
Dictionary: represents a collection of keys and values.
List: the generic counterpart of the ArrayList collection.
Queue: the generic counterpart of the non-generic Queue collection.
Stack: the generic counterpart of the non-generic Stack collection

No comments:

Post a Comment