Base Keyword
3 min readBase Keyword
TL;DR
In object-oriented programming (especially in C#), the keyword base is used inside a derived class to refer to its immediate parent (base) class.
How it works
Here’s what that means, clearly and simply:
✅ What “immediate base class” refers to
If you have a class that inherits from another class, the class it inherits from is called its base class. Inside the derived class, the keyword base lets you access:
- The base class’s methods
- The base class’s properties
- The base class’s constructors
- The base class’s indexers
…even if they are hidden or overridden in the derived class.
📌 Example
class Animal
{
public void MakeSound()
{
Console.WriteLine("Animal sound");
}
}
class Dog : Animal
{
public void MakeSound()
{
Console.WriteLine("Dog sound");
}
public void CallBaseSound()
{
base.MakeSound(); // calls Animal.MakeSound()
}
}
Here:
Animalis the base class.Dogis the derived class.- Inside
Dog, the keywordbaserefers specifically to Animal, which is the immediate parent.
📌 Why "immediate" base class?
If there is a long inheritance chain, like:
Animal → Mammal → Dog
Inside Dog, base always means Mammal, not Animal. So base refers only to the direct parent class.
âś” Summary
base= direct parent class of the current class- Used to access overridden or hidden members of the parent class
- Also used to call parent class constructors
If you want, I can also explain how base differs from this, or how it’s used in constructors.
Quick recall Q&A
base reference inside a derived class?The immediate parent class—not grandparents. In a chain Animal → Mammal → Dog, base inside Dog refers to Mammal.
When the base class lacks a parameterless constructor or you must initialize base state with specific arguments. Use : base(args) in the derived constructor.
base differ from this?this refers to the current instance (including overridden members). base lets you access the base implementation, bypassing overrides in the derived class.
base?No. base respects access modifiers. You can call protected/internal members exposed by the base class.
base.Method() inside an override?When you want to extend base behavior rather than replace it entirely—e.g., log additional data before or after invoking the base implementation.
Exceptions propagate like any method call; wrap base calls in try/catch only when you can handle failures meaningfully.
base equivalent?No. base only applies to classes/structs. Interfaces support default implementations in C# 8+, but you don’t call them via base.
Within a derived class, you can call base[index] to use the parent’s indexer when overriding.
Use base.Property or base.Event to interact with the parent’s implementation when overriding getters/setters or event accessors.
base behave in multiple inheritance?C# classes don’t support multiple inheritance, so base is always unambiguous. With interfaces, you implement each separately; no base keyword exists for them.