How to Pass Primary Constructor Parameters to a Base Class in C#
A class with a primary constructor takes its parameters in the class line itself. When it derives from a class that needs constructor arguments, it passes them in that same line, right after the base class's name.
Syntax
class <Derived>(<type> <parameter>, ...) : <Base>(<arguments>)
{
}
| Part | What it does |
|---|---|
<Derived>(<type> <parameter>, ...) | The derived class's primary constructor: its parameters |
: <Base> | The class it derives from |
(<arguments>) | The arguments for the base class's constructor, which can use the primary constructor's parameters |
Microsoft's primary constructors tutorial: "You can invoke the primary constructor for a base class from the primary constructor of derived class." And about its own example: "This expression specifies both the type for the base class and the arguments for the primary constructor."
The Example
An Animal class takes a name and keeps it in a Name property. A Dog takes a name too, passes it on to Animal, and adds a Speak method that uses Name.
Prerequisites
- The .NET 10 SDK or newer, which runs a single
.csfile withdotnet run. This guide uses .NET SDK 10.0.404.
Step 1: Write the Code
Create a file named main.cs in an empty folder:

Dog dog = new("Rex");
dog.Speak();
class Animal(string name)
{
public string Name { get; } = name;
}
class Dog(string name) : Animal(name)
{
public void Speak() => Console.WriteLine($"{Name} says woof.");
}
Dog(string name) : Animal(name) hands the name Dog received to Animal's constructor.
Step 2: Run It
dotnet run main.cs
Rex says woof.

new("Rex") went to Dog's primary constructor, which passed "Rex" to Animal's. Animal stored it in Name, and Speak, in Dog, read it from there.
The command is the same in zsh, bash and PowerShell.
Without the Arguments
Leave the arguments off the base class:
class Dog(string name) : Animal
{
public void Speak() => Console.WriteLine($"{Name} says woof.");
}
/Users/you/demo/main.cs(9,7): error CS7036: There is no argument given that corresponds to the required parameter 'name' of 'Animal.Animal(string)'
/Users/you/demo/main.cs(9,18): warning CS9113: Parameter 'name' is unread.
The build failed. Fix the build errors and run again.
- CS7036: Animal's only constructor needs a
name, and nothing gave it one. - CS9113: Dog's
nameparameter is now used nowhere, so the compiler says it's unread.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
: Animal without arguments, when Animal's constructor needs them | error CS7036: There is no argument given that corresponds to the required parameter 'name' of 'Animal.Animal(string)' | : Animal(name) |
| A primary constructor parameter that's never used | warning CS9113: Parameter 'name' is unread. | Use it, or remove it |
| Reading the parameter in Dog's methods as well as passing it on | warning CS9107: Parameter 'string name' is captured into the state of the enclosing type and its value is also passed to the base constructor. The value might be captured by the base class as well. | Read the base class's property, Name, as Speak does |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
CS7036 on the derived class's line | No arguments for the base class's constructor | Add them after the base class's name |
CS9113 on a primary constructor parameter | The parameter isn't passed on or used | Pass it to the base class, or use it |
CS9107 on the base class's arguments | The derived class reads the parameter too, so two copies may be kept | Read the base class's property instead |
FAQ
Does the base class need a primary constructor too?
No. Microsoft's guide to constructor errors: "The base class must have a matching constructor, but it doesn't need a primary constructor."
Can the arguments be expressions?
Yes. With class Dog(string name) : Animal(name.ToUpperInvariant()), the same program printed REX says woof.: Animal got the name in capitals.
Conclusion
To pass a primary constructor's parameters to a base class, write the arguments after the base class's name in the class line: class Dog(string name) : Animal(name). Without them, a base class whose constructor needs arguments stops the build with CS7036.
Additional Resources
- Declare primary constructors for classes and structs, on Microsoft Learn.
- Instance constructors: primary constructors, on Microsoft Learn.
- Resolve errors and warnings for constructor declarations, on Microsoft Learn.
