Skip to content
Search lessons, topics, tests…
Esc

    ↑ ↓ moveEnter openEsc close
    C# Language: all courses in this track

    Guided course · C# Language

    C# Internals: Value Types, Reference Types and the Heap

    How value types and reference types really work: the stack-versus-heap truth, a precise storage model, boxing, the large-struct trap and a framework for choosing between struct and class, with a quiz, a coding exercise and a benchmark. This is not a memorization handout. It is a guided model-building exercise. Read one section, run the code, redraw the memory picture from memory, and then explain the result aloud. If your explanation uses the words “it just does that,” the model is not yet complete. Recommended learning loop: Predict first. Before reading an output or diagram, write what you expect. Trace the bits. Ask: what exact value is copied, and where is the destination storage? Inspect lower layers. Compare C# semantics, representative IL, and likely JIT behavior. Measure. Use BenchmarkDotNet only after you can state a hypothesis. Teach it back. Explain the concept without saying “structs are on the stack.” Scope boundary: This course deliberately masters one foundation: value semantics versus reference semantics, and how those semantics relate to storage. Boxing, ref/in/out, ref struct, string interning, and advanced GC behavior are introduced only where they clarify this model. Boxing and ref/in/out have their own courses. Mastery gate: Do not continue past this course until you can answer all four questions without guessing: What does a variable of a value type contain? What does a variable of a reference type contain? Why can a struct live inside a heap object? Why is a reference-type parameter still passed by value unless marked ref, in, or out? Lesson thesis: Type category answers a semantic question. Storage location answers a placement question. They are related, but they are not the same question.

    Advanced6 modules · 22 lessons · 3 h 36 min · 1 free

    Module 1 · Value and Reference Types

    3 lessons · 24 min
    1. 01The first-principles machine modelFree3 min
    2. 02Value types: the variable contains the value (included with Full Access)10 min
    3. 03Reference types: the variable contains a reference (included with Full Access)11 min

    Module 2 · Stack, Heap and Boxing

    4 lessons · 32 min
    1. 04The stack-vs-heap truth (included with Full Access)4 min
    2. 05Under the hood: from C# to IL and machine code (included with Full Access)8 min
    3. 06A precise storage matrix (included with Full Access)11 min
    4. 07Boxing: when a value becomes an object (included with Full Access)9 min

    Module 3 · Designing Structs and Classes

    4 lessons · 27 min
    1. 08Bad versus good type design (included with Full Access)4 min
    2. 09The large-struct trap and by-reference passing preview (included with Full Access)9 min
    3. 10Common myths dismantled, and a worked trace (included with Full Access)4 min
    4. 11Decision framework: struct or class? (included with Full Access)10 min

    Module 4 · Practice, Benchmarks and Mastery

    4 lessons · 35 min
    1. 12Quiz: answer before checking the code (included with Full Access)9 min
    2. 13Coding exercise: build and explain (included with Full Access)9 min
    3. 14Performance challenge: BenchmarkDotNet (included with Full Access)10 min
    4. 15Mastery checklist and teach-back template (included with Full Access)7 min

    Module 5 · Reference Sheet and Sources

    2 lessons · 15 min
    1. 16Appendix A: compact reference sheet (included with Full Access)9 min
    2. 17Appendix B: sources and further reading (included with Full Access)6 min

    Module 6 · Module Practice Tests and Final Mock

    5 lessons · 1 h 23 min
    1. 18Practice Test: Value and Reference Types (included with Full Access)12 min
    2. 19Practice Test: Stack, Heap and Boxing (included with Full Access)12 min
    3. 20Practice Test: Designing Structs and Classes (included with Full Access)12 min
    4. 21Practice Test: Practice, Benchmarks and Mastery (included with Full Access)12 min
    5. 22Final Mock Interview: 25 Questions on C# Value Types, Reference Types and the Heap (included with Full Access)35 min