C# Constructor Overloading: Syntax and Usage
Learn how to declare multiple constructors in C#, how overload resolution works, and when to choose constructor overloading over optional parameters or factory methods.

Constructor overloading in C# lets a class expose multiple initialization paths while keeping construction logic centralized. Instead of forcing callers to pass every possible argument, you can define several constructors that share the same name but differ in parameter lists. This article covers the syntax, how overload resolution works, common pitfalls, and when to choose constructor overloading over optional parameters or factory methods.
What Constructor Overloading Means in C#
Constructor overloading is the ability to define more than one constructor in a class, each with a different signature. The signature includes the number, type, and order of parameters. The compiler selects the matching constructor based on the arguments supplied at the call site.
public class Order
{
public int Id { get; }
public string CustomerName { get; }
public decimal Total { get; }
public Order(int id, string customerName, decimal total)
{
Id = id;
CustomerName = customerName;
Total = total;
}
public Order(int id, string customerName)
: this(id, customerName, 0m)
{
}
}The second constructor delegates to the first using this, avoiding duplication. This is a common pattern when you want to provide sensible defaults.
Declaring Multiple Constructors: Syntax and Rules
A constructor is declared with the class name and a parameter list. Overloaded constructors must differ in parameter count or types. You cannot overload solely by return type or parameter names because the compiler uses the signature for resolution.
public class Logger
{
public Logger(string filePath) { /* ... */ }
public Logger(string filePath, bool append) { /* ... */ }
public Logger(Stream output) { /* ... */ }
}These three constructors are valid because each has a unique parameter list. The first two differ in parameter count; the third differs in parameter type. The compiler resolves the call based on the arguments you pass.
How Overload Resolution Works
When you instantiate a class, the compiler examines the arguments and picks the best matching constructor. It applies standard overload resolution rules: exact matches are preferred over implicit conversions, and more specific types are chosen over less specific ones.
var log1 = new Logger("app.log");
var log2 = new Logger("app.log", true);
var log3 = new Logger(new MemoryStream());If a call is ambiguous, the compiler produces an error. For example, having both Logger(string) and Logger(object) makes new Logger(null) ambiguous because null is compatible with both. You must cast to disambiguate: new Logger((string)null).
Practical Example: A Configuration Class
Consider a DatabaseConfig class that needs to support multiple ways to be constructed: from a connection string, from individual components, or from another configuration object.
public class DatabaseConfig
{
public string Server { get; }
public string Database { get; }
public string User { get; }
public string Password { get; }
public DatabaseConfig(string connectionString)
{
// Parse connection string and assign properties
}
public DatabaseConfig(string server, string database, string user, string password)
{
Server = server;
Database = database;
User = user;
Password = password;
}
public DatabaseConfig(DatabaseConfig other)
{
Server = other.Server;
Database = other.Database;
User = other.User;
Password = other.Password;
}
}The copy constructor is useful when you need to clone an existing configuration without exposing mutable state. Overloading here provides a clear API for different initialization scenarios.
Common Mistakes and Ambiguities
One frequent mistake is trying to overload only by parameter names. C# constructor signatures include the number, types, and order of parameters, but not their names, so these two declarations cause a compile-time error:
public class Example
{
public Example(int x) { }
public Example(int y) { } // Error: same parameter types as the first constructor
}Parameter names are still useful with named arguments (new Example(x: 1)), but they do not create a distinct overload. Also avoid mixing optional parameters with overloads in the same parameter set; a call with fewer arguments can be ambiguous or resolved to an overload you did not intend. Choose one style for a given set of parameters.
Another issue is overloading with null-compatible types, as mentioned earlier. When a caller passes null, the compiler cannot decide between string and object overloads. This often forces callers to cast, which is ugly. Consider whether such overloads are truly necessary.
Runtime Cost and Maintainability
Constructor overloading itself has no runtime cost. The compiler resolves overloads at compile time, so the generated IL simply calls the selected constructor. The cost of object initialization is the same as with a single constructor; the overhead is in the constructor body, not in the selection process.
From a maintainability perspective, too many overloads can make a class hard to understand. Each constructor is a separate entry point, and callers must know which one to use. If you find yourself adding many overloads to support every combination of parameters, consider using optional parameters or a builder pattern instead. A good rule of thumb is to keep the number of constructors small and use constructor chaining to centralize logic.
Constructor chaining with this reduces duplication but also creates a dependency chain. If the target constructor changes, all chained constructors are affected. This is usually beneficial, but it means you must be careful about the order of initialization and any side effects.
When to Prefer Overloads Over Optional Parameters or Factory Methods
Overloads are appropriate when different parameter sets represent genuinely different ways to initialize an object. For example, a constructor that takes a connection string and one that takes separate components are distinct enough to warrant separate signatures.
Optional parameters are a better fit when you have a single logical set of parameters with sensible defaults. For example, Logger(string filePath, bool append = false) is clearer than having two constructors.
Factory methods (static methods that return an instance) are useful when construction involves complex logic, validation, or when you want to give the creation method a descriptive name, such as DatabaseConfig.FromConnectionString(...). They also allow you to return a different type or a cached instance.
| Approach | Best used when | Example |
|---|---|---|
| Overloaded constructors | Distinct initialization paths with different parameter types or counts | Order(int, string, decimal) vs Order(int, string) |
| Optional parameters | One logical set of parameters with defaults | Logger(string path, bool append = false) |
| Factory methods | Complex construction, validation, or descriptive creation | DatabaseConfig.FromConnectionString(...) |
The decision depends on how much the call sites differ and how much logic you need to hide. Overloads are a language-level feature that keeps construction inside the class, while factory methods give you more control over the creation process.
Constructor Chaining and the this Keyword
Constructor chaining is closely related to overloading. It lets one constructor call another in the same class, reducing duplication and ensuring consistent initialization.
public class Product
{
public string Sku { get; }
public string Name { get; }
public decimal Price { get; }
public Product(string sku, string name, decimal price)
{
Sku = sku;
Name = name;
Price = price;
}
public Product(string sku, string name)
: this(sku, name, 0m)
{
}
}The second constructor passes a default price of zero to the first. This pattern is safe as long as the target constructor does not perform work that the shorter constructor is meant to skip. If zero is not a valid price, a validating target constructor would reject the default, so chaining would not work. In that case, assign properties directly in each constructor instead.
That's a subtle point: chaining forces all constructors to go through the same validation. If different overloads need different validation rules, chaining may not be appropriate. Evaluate whether the shared logic is truly common before using this.
Try matching browser tools
All toolsSmall utilities that fit C# work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related C# guides
All C# guidesC# Dispose vs Destructor: Key Differences Explained
c# dispose vs destructor: Understand the difference between Dispose and destructors in C#, when each runs, and how to manage unmanaged resources correctly.
C# Variable Declaration: Syntax and Practical Usage
Learn how to declare variables in C# with explicit types, var, and nullable annotations, and understand how defaults, scope, and readability affect your choices.
C# Primary Constructors for Classes: Syntax and Usage
Learn how to use C# primary constructors for classes: syntax, initialization, dependency injection, and limitations with practical examples.
C# IComparer: Custom Sorting with IComparer<T>
Learn how to implement IComparer<T> in C# to define custom sort order for arrays and lists, handle nulls, and avoid common performance pitfalls.
More in C#
All C# guidesThe guides filed next to this one in C#, in library order.