C# › Fundamentals

What are auto-implemented properties, and what does the compiler generate behind the scenes for one?

Beginner

Answer

An auto-property (`public string Name { get; set; }`) lets you declare a property without writing an explicit backing field or accessor bodies — the compiler automatically generates a hidden private backing field and simple get/set accessor implementations for you.
public class Person {
  public string Name { get; set; } = string.Empty; // compiler generates the backing field automatically
  public int Age { get; init; } // init-only: settable only during object initialization
}
Real-world example Quickly defining simple data-holder properties on a class without writing repetitive backing-field boilerplate.

Common follow-ups: What does the 'init' accessor (instead of 'set') restrict about when a property can be assigned?