← Back
Nick Chapsas August 1, 2024 38s

Be Careful with Primary Constructors in C# | .NET Tips 12

Summary

Primary constructors in C# 12, while excellent for tidying classes, have a significant limitation: they don't support defining `readonly` fields. This prevents immutable service injection, leading to worse code if refactoring is applied without understanding this constraint. Developers must be cautious when using primary constructors to avoid this practical issue.

View original episode ↗