C# .NET – Collections Comparison

generic.net.collection.interfaces

I liked a James Michael Hare’s post “C#/.NET Fundamentals: Choosing the Right Collection Class“, and I like to re-blog the comparison table:

Collection Ordering Contiguous Storage? Direct Access? Lookup Efficiency ManipulateEfficiency Notes
Dictionary Unordered Yes Via Key Key:O(1) O(1) Best for high performance lookups.
SortedDictionary Sorted No Via Key Key: O(log n) O(log n) Compromise of Dictionary speed and ordering, uses binarysearch tree.
SortedList Sorted Yes Via Key Key:O(log n) O(n) Very similar toSortedDictionary, except tree is implemented in an array, so has faster lookup on preloaded data, but slower loads.
List User has precise control over element ordering Yes Via Index Index: O(1)
Value: O(n)
O(n) Best for smaller lists where direct access required and no sorting.
LinkedList User has precise control over element ordering No No Value:O(n) O(1) Best for lists where inserting/deleting in middle is common and no direct access required.
HashSet Unordered Yes Via Key Key:O(1) O(1) Unique unordered collection, like a Dictionary except key and value are same object.
SortedSet Sorted No Via Key Key:O(log n) O(log n) Unique sorted collection, like SortedDictionary except key and value are same object.
Stack LIFO Yes Only Top Top: O(1) O(1)* Essentially same as List except only process as LIFO
Queue FIFO Yes Only Front Front: O(1) O(1) Essentially same as List except only process as FIFO
Advertisements

PASS SQL Saturday Parma Agenda now available!

Alessandro Alpi's Blog

PASS SQL Saturday Parma agenda is now available!

This is the timetable:
From        To
————————–
10:00       11:00
11:15       12:15
12:30       13:30
13:30       14:30
14:30       15:30
15:45       16:45
16:45       17:00
17:00       18:00
————————–
 
We will have three tracks:
  • BI, for Business Intelligence, BigData, xVelocity, etc.
  • DEV, for developers 
  • OPS, for operations and administration
Checkout the agenda here and organize your Saturday with the schedule builder!
 
Stay Tuned! 🙂
 
 
 
 

View original post