Skip to content

Auto implemented properties

Context: Auto‑implemented properties simplify syntax by letting the compiler generate a hidden backing field.

public string Name { get; set; }
public int Age { get; set; } = 18; // with default
public string Id { get; } // can be set only in constructor
public DateTime CreatedAt { get; init; }
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
}
// Usage
var product = new Product { Id = 1, Name = "Laptop", Price = 999.99M };

The compiler generates a private field like _<PropertyName>k__BackingField.