Guided course · C# Language
C# Internals: ref, in, out and Byref Aliasing
Passing by value and by reference in C#: byrefs and aliasing, ref, out and in parameters, readonly refs and defensive copies, ref returns and escape rules, and the copy-versus-alias cost trade-off, with IL inspection and a benchmark.
Advanced10 modules · 44 lessons · 5 h 14 min · 2 free
Module 1 · Values, Parameters and Byrefs
4 lessons · 11 min- 01A value is not a variable, and assignment vs ref assignmentFree3 min
- 02Parameters are passed by value, and the cost of large structsFree3 min
- 03Byrefs: addresses to typed storage, and where they come from (included with Full Access)3 min
- 04ref parameters: the source-level contract and its lowering (included with Full Access)2 min
Module 2 · Aliasing, out and in Parameters
4 lessons · 11 min- 05Aliasing is observable, and what out adds to a byref (included with Full Access)3 min
- 06out as a language contract, and the Try pattern vs tuples (included with Full Access)3 min
- 07in parameters and compiler-generated temporaries (included with Full Access)3 min
- 08Explicit in and overload intent (included with Full Access)2 min
Module 3 · Readonly Refs and Defensive Copies
4 lessons · 19 min- 09Defensive copies and how to fix them (included with Full Access)4 min
- 10ref readonly parameters and readonly ref returns (included with Full Access)3 min
- 11Ref locals: a local variable can be an alias (included with Full Access)9 min
- 12Readonly ref locals, and properties as values (included with Full Access)3 min
Module 4 · Ref Returns and Escape Rules
4 lessons · 27 min- 13Ref returns: the caller receives an alias (included with Full Access)11 min
- 14Escaping invariants, and how dangling references are prevented (included with Full Access)10 min
- 15scoped, and why heap objects cannot hold byref fields (included with Full Access)4 min
- 16Two readonly dimensions, and a preview of Span<T> (included with Full Access)2 min
Module 5 · Copy Cost, Alias Cost and the GC
4 lessons · 18 min- 17Mutating array elements in place, and ref iteration over Span<T> (included with Full Access)3 min
- 18Copy cost vs alias cost: no universal size threshold (included with Full Access)2 min
- 19What aliasing can cost: allocation, lifetime and write barriers (included with Full Access)3 min
- 20Interior byrefs, object lifetime and pinning (included with Full Access)10 min
Module 6 · Ref Patterns and Pitfalls
4 lessons · 35 min- 21Write barriers, thread safety and expected failure with out (included with Full Access)2 min
- 22Patterns: ref accumulators, in for large values, ref readonly access (included with Full Access)11 min
- 23Classes rarely need ref, and common misuse cases (included with Full Access)12 min
- 24Writable ref returns break encapsulation (included with Full Access)10 min
Module 7 · Inspecting IL and Allocations
4 lessons · 28 min- 25A traced program: memory model and step-by-step execution (included with Full Access)3 min
- 26Inspecting IL, JIT assembly and allocations (included with Full Access)3 min
- 27Coding exercise: goal and starter types (included with Full Access)9 min
- 28Coding exercise: requirements (included with Full Access)13 min
Module 8 · Exercise, Benchmark and Quiz
4 lessons · 9 min- 29Coding exercise: tests, implementation and memory diagram (included with Full Access)2 min
- 30Benchmark: project setup and predictions (included with Full Access)2 min
- 31Benchmark: record results and investigate (included with Full Access)2 min
- 32Quiz and self-assessment (included with Full Access)3 min
Module 9 · Reference Matrices
2 lessons · 13 minModule 10 · Module Practice Tests and Final Mock
10 lessons · 2 h 23 min- 35Practice Test: Values, Parameters and Byrefs (included with Full Access)12 min
- 36Practice Test: Aliasing, out and in Parameters (included with Full Access)12 min
- 37Practice Test: Readonly Refs and Defensive Copies (included with Full Access)12 min
- 38Practice Test: Ref Returns and Escape Rules (included with Full Access)12 min
- 39Practice Test: Copy Cost, Alias Cost and the GC (included with Full Access)12 min
- 40Practice Test: Ref Patterns and Pitfalls (included with Full Access)12 min
- 41Practice Test: Inspecting IL and Allocations (included with Full Access)12 min
- 42Practice Test: Exercise, Benchmark and Quiz (included with Full Access)12 min
- 43Practice Test: Reference Matrices (included with Full Access)12 min
- 44Final Mock Interview: 25 Questions on C# ref, in, out and Byref Aliasing (included with Full Access)35 min