C# Feature – Auto-implemented properties
Overview
Section titled “Overview”Auto-properties remove the need for explicit backing fields when no custom logic is required.
Introduced In
Section titled “Introduced In”C# 3 (2007)
Before
Section titled “Before”private string _name;public string Name { get => _name; set => _name = value; }
public string Name { get; set; }
Annotated Example
Section titled “Annotated Example”public class Person { public string Name { get; init; } }
Gotchas & Best Practices
Section titled “Gotchas & Best Practices”- Use
init
for immutability where possible (C# 9).
Related Features
Section titled “Related Features”Version Notes
Section titled “Version Notes”init
added in C# 9; required members in C# 11.