Constructor Chaining
noun
say it: “kun-STRUK-ter CHAYN-ing” /kənˈstrʌktər ˈtʃeɪnɪŋ/
One constructor calling another, with : this(...) or : base(...), so setup code is written once.
What is Constructor Chaining in C#?
Constructor Chaining — Calling another constructor so initialization logic can be reused.
class Store
{
static int locationCount = 3;
const int maxItems = 100;
readonly string name;
Store(string name)
{
this.name = name;
}
}
In a sentence
- “With constructor chaining, the one-argument constructor calls the full one with a default price.”
Level: Journeyman · More C# terms at this level
Updated