> ## 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# Public Property

A public property in C# is a member of a class, struct, record, or interface that provides controlled read and/or write access to an object's instance state or a type's static state. It combines the syntax of a field with the semantics of a method by encapsulating data behind `get`, `set`, or `init` accessor blocks. The `public` access modifier declares that the property is accessible to any code that can access the property's containing type. A member's accessibility is strictly capped by its containing type's accessibility; therefore, a `public` property inside an `internal` class remains completely inaccessible to referencing assemblies.

## Auto-Implemented Properties

When custom logic is not required within the accessors, C# provides auto-implemented properties. The compiler automatically generates a hidden, anonymous private backing field to store the data.

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

## Explicit Backing Fields (Full Properties)

When you need to intercept data during retrieval or assignment, you define a full property with an explicit private backing field. The `set` and `init` accessors utilize an implicit parameter named `value`, which holds the data being assigned.

```csharp theme={"dark"}
private int _capacity;

public int Capacity
{
    get 
    { 
        return _capacity; 
    }
    set 
    { 
        // 'value' is a contextual keyword representing the assigned data
        _capacity = value; 
    }
}
```

## Accessor Types

A public property can implement the following accessors to provide read-only, write-only, or read-write access:

* **`get`**: Executes when the property is read. It must return a value matching the property's type.
* **`set`**: Executes when the property is assigned a new value.
* **`init`**: A specialized setter introduced in C# 9.0 that restricts assignment to the object's initialization phase (object initializers or constructors), rendering the property immutable thereafter.

```csharp theme={"dark"}
public DateTime CreatedAt { get; init; }
```

## Expression-Bodied Properties and Accessors

For properties or accessors containing a single expression, C# supports expression body definitions using the `=>` (lambda) operator. An expression-bodied property omits the `get` keyword entirely and is implicitly read-only. Alternatively, full properties can utilize expression-bodied `get` and `set` accessors.

```csharp theme={"dark"}
private string _prefix;
private string _suffix;

// Expression-bodied property (implicitly read-only, omits 'get' keyword)
public string Combined => $"{_prefix}-{_suffix}"; 

// Expression-bodied accessors (C# 7.0+)
public string Prefix
{
    get => _prefix;
    set => _prefix = value;
}
```

## Static Properties

Properties can be declared with the `static` modifier. A public static property manages state at the type level rather than the instance level, making it accessible via the type name itself.

```csharp theme={"dark"}
public static int GlobalInstanceCount { get; private set; }
```

## Asymmetric Accessor Accessibility

While the property itself is declared `public`, you can apply a more restrictive access modifier to an individual accessor to limit mutation or retrieval scopes. The modifier applied to the accessor must be strictly more restrictive than the property's declared accessibility.

Under C# compiler rules, when defining asymmetric accessibility, you are only allowed to apply an access modifier to *one* of the accessors (either `get` or `set`/`init`), not both. Specifying modifiers on both accessors results in a compiler error (CS0274).

```csharp theme={"dark"}
// Globally readable (subject to type visibility), but only mutable from within the declaring type
public double Temperature { get; private set; }
```

<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>
