Part 06 of a hands-on C# practice series. The topics that famously decide interviews: value vs reference types (with the nuance most people miss), boxing measured in megabytes, mutable-struct horror stories, GC generations watched live via GC.GetGeneration, and IDisposable/using ownership rules.
dotnet run # all examples
dotnet run 3 # just one (e.g. structs)| # | Topic | Highlights |
|---|---|---|
| 01 | Value vs reference | copy vs share, ref/out/in, "the reference is passed by value", where values really live |
| 02 | Boxing | identity split, wrong-type unbox, 1M boxes measured in MB, sneaky boxing sites |
| 03 | Structs vs classes | readonly record struct Money, the vanishing increment horror, ≤16-byte guidance |
| 04 | Garbage collector | generations watched live, LOH, roots, why GC.Collect() is wrong |
| 05 | IDisposable | three spellings of using, dispose-on-exception, IAsyncDisposable, ownership rules |
- "The reference itself is passed by value" — explains every parameter puzzle.
- "Value types live inline in their container — the container decides stack vs heap."
- "Unbox must match the exact type;
(long)boxedIntthrows." - "Dispose is about non-memory resources and timing; the GC is about memory."
- "Leaks in C# are accidental reachability: static lists, forgotten
-=, unbounded caches."
- Value types vs reference types
- Boxing and unboxing
- Fundamentals of garbage collection
- Implementing Dispose
← Previous: 05 Generics · Next: 07 Exceptions →
| Part | Topic |
|---|---|
| 01 | Collections |
| 02 | LINQ |
| 03 | Delegates & events |
| 04 | Async/await |
| 05 | Generics |
| 06 | Types & memory (this repo) |
| 07 | Exceptions |
| 08 | Modern C# 8–12 |
| 09 | Strings & text |
| 10 | Files & JSON |
| 11 | MiniShop microservices (finale) |
Matej Zlatunić
Released under the MIT License. Feel free to use it for learning.