---
source: https://iinventedlight.com/library/notes/csharp-properties.md
title: "C# properties"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC BY 4.0 (dotnet/docs); prose restates cited source lines"
attribution: "Summary by iinventedlight (AI-assisted). Sources: Microsoft Learn (.NET docs), Properties - C#, CC BY 4.0 (dotnet/docs); Microsoft Learn (.NET docs), Using Properties - C#, CC BY 4.0 (dotnet/docs)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: C#"
tags: ['csharp', 'dotnet', 'properties', 'classes']
sources:
  - id: S1
    title: "Properties - C#"
    publisher: Microsoft Learn (.NET docs)
    url: https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties
    accessed: 2026-11-04
    license: "CC BY 4.0 (dotnet/docs)"
  - id: S2
    title: "Using Properties - C#"
    publisher: Microsoft Learn (.NET docs)
    url: https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/using-properties
    accessed: 2026-11-04
    license: "CC BY 4.0 (dotnet/docs)"
---
# C# properties

**Answer:** A C# property looks like a field to callers but runs `get` and `set` (or `init`) accessors. Unlike fields, properties are not variables, so they cannot be passed as `ref` or `out`.

```csharp
public class Person {
  public required string FirstName { get; init; }
  public string LastName { get; private set; } = "";
  public string Name => $"{FirstName} {LastName}";   // computed
}
```

- `Name` has no backing field and is computed on each read.

## Custom accessors

```csharp
private int _age;
public int Age {
  get => _age;
  set {
    if (value < 0) throw new ArgumentOutOfRangeException(nameof(value));
    _age = value;
    AgeChanged?.Invoke(this, EventArgs.Empty);
  }
}
```

A `get` accessor must return or throw.

## Claims
- id: C1
  claim: The Name property is computed with no backing field.
  source: S1
  evidence: "The Name property is a computed property. There's no backing field for Name."
- id: C2
  claim: Simple properties can be auto-implemented.
  source: S1
  evidence: "can be implemented either as expression body definitions or as automatically implemented properties."
- id: C3
  claim: You can't pass a property as a ref or out parameter.
  source: S2
  evidence: "Therefore, you can't pass a property as a ref or out parameter."
- id: C4
  claim: Properties can take an action when data changes, such as raising an event.
  source: S2
  evidence: "They can take an action when data is changed, such as raising an event"

## Sources
- [S1] Properties - C#. Microsoft Learn (.NET docs). https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties . License: CC BY 4.0 (dotnet/docs). Accessed 2026-11-04.
- [S2] Using Properties - C#. Microsoft Learn (.NET docs). https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/using-properties . License: CC BY 4.0 (dotnet/docs). Accessed 2026-11-04.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
