C# Collections

Collections: Easy way to work with a group of objects.

Types of C# collection classes:

  • System.Collections.Generics: Group compatible type of object
  • System.Collections: Group objects of different types
  • System.Collections.Concurrent: Help to achieve Threat-Safe code (multiple threads accessing concurrently).

System.Collections.Generics

  • List<T>: Access by index
  • Stack: Elements stored a LIFO (Last In First Out): Push & Pop methods.
  • Queue: Elements stored as FIFO (First In Firs Out): Enqueue & Dequeue methods.
  • SortedList<TKey, TValue>: key/value pairs sorted in an order.
  • Dictionary<Tkey, TValue>: key/value pairs without an specific order

System.Collections

  • ArrayList: Can contain diferent objects types. Can sort.
  • Hashtable: key/value pairs managed with the hash of the key.

System.Collections.Concurrent

  • ConcurrentStack
  • ConcurrentQueue
  • ConcurrentDictionary