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.
public class Person {
public required string FirstName { get; init; }
public string LastName { get; private set; } = "";
public string Name => $"{FirstName} {LastName}"; // computed
}
Namehas no backing field and is computed on each read.
Custom accessors
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).
License: CC-BY-4.0 · 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).
Cite this
iinventedlight. 2026. "C# properties." iinventedlight Library, iil:note:b4zntcnj, version of 2026-11-04. https://iinventedlight.com/library/notes/csharp-properties/. License: CC-BY-4.0.
@misc{iil_note_b4zntcnj,
author = {{iinventedlight}},
title = {{C\# properties}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/csharp-properties/},
note = {Permanent ID iil:note:b4zntcnj. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/csharp-properties.md.