C# primary constructors
Answer: The parameters are in scope throughout the type body.
public class OrderService(IOrderRepo repo, ILogger<OrderService> log) {
public Order Get(int id) {
log.LogInformation("Get {Id}", id);
return repo.Find(id);
}
}
Other constructors must chain
Additional constructors must call the primary one with this(...):
public class Point(int x, int y) {
public Point() : this(0, 0) {}
public int X => x;
}
If a class has no explicit constructor, C# supplies a parameterless one; declaring a primary constructor replaces that default.
Claims
- id: C1 claim: C# 12 introduces primary constructors. source: S1 evidence: "C# 12 introduces primary constructors"
- id: C2 claim: Primary constructor parameters aren't members of the class. source: S1 evidence: "Primary constructor parameters aren't members of the class."
- id: C3 claim: Primary constructor parameters don't become properties, except in records. source: S1 evidence: "Primary constructor parameters don't become properties, except in record types."
- id: C4 claim: A constructor can call another using the this keyword. source: S2 evidence: "To do that, use the this keyword."
- id: C5 claim: C# provides a parameterless constructor if none is declared. source: S2 evidence: "C# provides a parameterless constructor that you can use to instantiate an instance"
Sources
- [S1] Declare C# primary constructors – classes, structs. Microsoft Learn (.NET docs). https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/primary-constructors . License: CC BY 4.0 (dotnet/docs). Accessed 2026-11-04.
- [S2] Instance constructors - C#. Microsoft Learn (.NET docs). https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/instance-constructors . 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), Declare C# primary constructors – classes, structs, CC BY 4.0 (dotnet/docs); Microsoft Learn (.NET docs), Instance constructors - C#, CC BY 4.0 (dotnet/docs).
Cite this
iinventedlight. 2026. "C# primary constructors." iinventedlight Library, iil:note:5wv1yt3d, version of 2026-11-04. https://iinventedlight.com/library/notes/csharp-primary-constructors/. License: CC-BY-4.0.
@misc{iil_note_5wv1yt3d,
author = {{iinventedlight}},
title = {{C\# primary constructors}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/csharp-primary-constructors/},
note = {Permanent ID iil:note:5wv1yt3d. 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-primary-constructors.md.