Skip to content

#16 Collections

Collections represent a set of objects that you can access by stepping through each element in turn, in short, they are used to store and retrieve data. The most interesting part of collections is that the memory can be allocated to them at runtime and can be accessed using index just like an array. Collections implement IEnumerable interface that is extended by ICollection interface. IDictionary and IList interfaces are also derived from ICollection which are part of Collection Namespace.

Collections are of 2 types

  • Generic Collections derived from System.Collections.Generic
  • Non -generic Collections derived from System.Collections
Generic CollectionDescription
List<T>Collection of similar elements with auto increment.
SortedList<Tkey,Tvalue>Collection of key-value pairs adds elements in ascending order of key by default.
Statck<T>Stores value as LIFO (Last In First Out).
Queue<T>Stores value as FIFO (First In First Out).
Hashset<T>It contains non-duplicate elements
Dictionary <Tkey, Tvalue>Contains key-value Pair
Non-Generic CollectionDescription
ArrayListCollection of similar elements with auto increment stored in continuous memory
SortedListCollection of key-value pairs adds elements in ascending order of key by default.
StackStores value as LIFO (Last In First Out).
QueueStores value as FIFO (First In First Out).
HashtableStores key-value pairs and retrieve the values by comparing the hash value of the keys
BitArrayA compact array of bit values represented as 1’s and 0’s
Published inC#

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *