Teach Yourself Computer Science
Data structures
In .Net…
Some differences:
- List persist order of the items, Dictionary does not
- List allow fast access by index
- List support built in QuickSort algorithm for fast data sorting
- Dictionary allows ~
O(1)time complexity to access an item (value) by a key
From the docs
The ContainsKey and Add method are close to O(1).
ContainsKey documentation:
This method approaches an O(1) operation.
Add documentation:
If Count is less than the capacity, this method approaches an O(1) operation. If the capacity must be increased to accommodate the new element, this method becomes an O(n) operation, where n is Count.
Time complexity
-
Constant time – O (1)
-
Linear time – O (n)
-
Logarithmic time – O (log n)
-
Quadratic time – O (n^2)
-
Cubic time – O (n^3)
Concurrency
Actor model
Basics
Value types vs reference types
Booleans, fixed-size integers, floats, and characters are typically value types — assigning or passing one copies the actual value. Objects are reference types — assigning or passing one copies the reference, not the underlying object, so both variables point at the same thing.
That distinction is why mutating a reference type through one variable is visible through any other reference to it, while mutating a value type never leaks across variables.
It’s also why reference types support identity (can ask “are these two references pointing at the same object?”) in a way value types don’t — two value-type variables holding 5 aren’t “the same 5”, they’re just equal.
Mechanically (in most managed runtimes): value types live on the stack or inline inside whatever contains them; reference types live on the heap, with only the reference itself living on the stack.