Unexpected inconsistency in records – Jon Skeet's coding blog
10 months ago
- #Records
- #C#
- #Programming
- The article discusses an unexpected inconsistency in C# records when using the 'with' operator for nondestructive mutation.
- It highlights a problem where derived data in records doesn't update correctly when using the 'with' operator, leading to incorrect property values.
- The author explores four potential solutions: avoiding the 'with' operator for complex records, writing a Roslyn analyzer, using Lazy<T> for safe computation, or requesting a language change.
- The conclusion emphasizes the need for awareness when using the 'with' operator with computed properties in records to avoid bugs.