Using Immutable Data Structures in C# and .NET
summary
Shows why open setters cause runtime NullReferenceExceptions by mutating shared Order objects and demonstrates a practical refactor that uses projection with LINQ to create display models instead of editing originals. Introduces System.Collections.Immutable via ImmutableList.Create, shows that AutoMapper/Json.NET support will construct immutable types, and recommends Builder and Factory patterns, constructor injection with ArgumentNullException checks, and mutating sparingly because EF requires mutability and won’t be replaced.
AI-written summary · about
chapters (11)
- 0:00Introduction to immutability
- 3:33Dangers of mutable code
- 9:10Reasoning about state
- 12:31Multi-threading and safety
- 15:13Evolution of C# immutability
- 19:01Leveraging LINQ and projection
- 23:29Refactoring for immutability
- 28:32Using immutable collections
- 30:32Library support
- 33:44Builder and factory patterns
- 40:02Pragmatic conclusions
related talks
47mUsing Immutable Data Structures in C# and .NET
50mImmutable code in .NET
54mImmutable Collections in NET: Why and How?
56mChange your habits: Modern techniques for modern C#
57m'nullable' enable – Unlock the Power of C# Nullability
01h 03mC# 7
01h 06mNull & Void - Everything about Nothing in .NET
54mAlgebraic Data Types for C#
