> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C# Auto-Implemented Property

An auto-implemented property is a concise syntax in C# that allows you to declare a property without explicitly defining a backing field. When the compiler encounters an auto-implemented property, it automatically generates a private, anonymous backing field that can only be accessed through the property's `get` and `set` accessors.

## Basic Syntax

To declare an auto-implemented property, you define the accessors without providing an implementation body.

```csharp theme={"dark"}
public string FirstName { get; set; }
```

Under the hood, the C# compiler translates the above declaration into an equivalent standard property with a hidden backing field. The generated code logically resembles the following:

```csharp theme={"dark"}
[CompilerGenerated]
private string <FirstName>k__BackingField;

public string FirstName
{
    get { return <FirstName>k__BackingField; }
    set { <FirstName>k__BackingField = value; }
}
```

## Accessor Accessibility

You can apply access modifiers directly to individual accessors to restrict visibility. The accessor modifier must be more restrictive than the property's overall access level.

```csharp theme={"dark"}
// The property can be read publicly, but only modified from within the defining class.
public int RecordId { get; private set; }

// The property can be read publicly, but only modified by the defining class or derived classes.
public decimal Balance { get; protected set; }
```

## Inline Initialization (C# 6.0+)

Auto-implemented properties can be assigned a default value directly at the point of declaration. This initializes the underlying compiler-generated backing field before the class constructor executes.

```csharp theme={"dark"}
public string Status { get; set; } = "Pending";
public int RetryCount { get; set; } = 3;
```

## Read-Only Auto-Properties (C# 6.0+)

You can declare an auto-implemented property with only a `get` accessor. The compiler generates a `readonly` backing field, meaning the property can only be assigned a value during inline initialization or within the class constructor.

```csharp theme={"dark"}
public class DatabaseContext
{
    public Guid CorrelationId { get; } = Guid.NewGuid();

    public string ConnectionString { get; }

    public DatabaseContext(string connectionString)
    {
        // Valid assignment for a get-only auto-property
        ConnectionString = connectionString; 
    }
}
```

## Init-Only Properties (C# 9.0+)

By replacing the `set` accessor with the `init` keyword, you create an auto-implemented property that can only be assigned a value during object creation (via an object initializer) or within the constructor. After initialization, the property itself cannot be reassigned. This enforces shallow immutability; if the property holds a reference type, the internal state of the referenced object can still be modified.

```csharp theme={"dark"}
public string ConfigurationHash { get; init; }
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C# Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
