Page Stats
Visitor: 212
C#.Net Collection
The size of arrays is fixed, if the number of elements is dynamic, you should use collection classes that hold many values or objects. Collection represents a set of objects that you can access by stepping through each element. The .NET framework provides specialized classes for managing collection and these classes have rich capability for enhancing your programming experience through better performance and easy maintenance. Object class is the base class of every type in .NET. All the collections implement IEnumerable interface that is extended by ICollection interface. IDictionary and IList are also interfaces for collection which are derived from ICollection.
Various Classes in Collection namespace are:
- ArrayList Class
- Stack Class
- Queue Class
- Linked List Class
- Dictionary
- Hashtable Class
- SortedList Class
Linked List Class
A linked list is a linear collection of self-referential class objects called nodes, connected by reference links. Data is stored in a linked list dynamically, each node is created as necessary.
Advantage of Linked List is:
Linked lists provide better memory utilization because they can grow and shrink at execution time thus, saves memory.
LinkedList <int> alist = new LinkedList <int>(); alist.AddFirst(10); alist.AddAfter(alist.Last ,20); alist.AddAfter(alist.Last, 30); alist.AddAfter(alist.Last, 40); foreach (int i in alist ) { Console.WriteLine(i); }