Data Structures in C#

Array

  • Continuous memory space
  • Quickly locate lookup elements with random access and high lookup efficiency
  • Known uniform element types, reducing runtime overhead
  • Fixed length, no new elements can be added

ArrayList

  • Continuous memory space
  • Fast element location, random access, efficient search
  • Variable length, easy to add or delete elements
  • Unknown element types, Runtime requires type detection, Runtime requires boxing and unboxing actions, which creates performance overhead
  • Can add, delete and change elements, need to re-adjust the position of subsequent elements, which generates performance overhead

List

  • Continuous memory space
  • Quickly locate and find elements with high random access and high efficiency
  • Variable length, easy to add and delete elements
  • Generic, uniform known types, avoid runtime type detection, avoid runtime boxing and unboxing, reduce runtime performance overhead
  • Can add, delete, and change elements, requiring repositioning of subsequent elements, resulting in performance overhead

LinkedList

  • Variable length, easy to add and delete nodes (elements)
  • Fast add/delete performance, does not affect other nodes (elements) position adjustment
  • Generic, uniform known types, avoid runtime type detection, avoid runtime boxing and unboxing, reduce runtime performance overhead
  • Unordered, decentralized storage, separated from each other, relying on the pointer in the node (element) to point to the associated next node (element)
  • Low lookup efficiency, no random lookup, no loop support, can only lookup the next node (element) from the first (last) node (element) by pointing to the next node (element) one by one

Stack

  • Stack: first-in, last-out, small, continuous, memory space for storing variables and parameters, fast reading speed
  • Heap: Unordered, memory area for storing data objects, relatively slow to read, manually releasable area

Queue

  • Linear, ordered, first-in-first-out
  • End-of-queue insertion, head-of-queue deletion
  • Sequential queue, expected length; chained queue, variable length

Dictionary

  • Hash storage structure, key-value pair access, fast lookup by index
  • Non-repeating keys, uniqueness
  • Traversable datasets
  • Generic, avoid runtime type detection, avoid runtime boxing and unboxing
  • Hash storage, no fixed length, no adjustment of element positions when adding or deleting

Leave a Reply