C# Base

5 Sept 2025 | 6 min read

In the C# programming language, the base keyword is utilized to access base class members from within the derived class. It helps to invoke the implementation of the parent class when it is overridden or when we need to call the parent constructor during the object creation. A base class keyword can only be used in an instance method, a constructor, or an instance property accessor.

Syntax:

It has the following syntax:

In this syntax,

  • MemberName: It is used to access the base class member.
  • :base(parmeter_list): It is used in the derived class constructor to call the base class constructor.

C# Base keyword to access the base class field

In C# programming, we can use the base keyword to access the fields of the base class inside the derived class. It can be beneficial if base and derived classes contain the same fields. If the derived class does not define the same field, there is no need to use the base keyword. Base class field can be directly accessed by the derived class.

C# Base keyword example to access the base class field

Let's see the simple example of a base keyword in C#, which accesses the field of the base class.

Output:

white
black

Explanation:

In this example, we demonstrate the field hiding wherein Dog possesses its own color field hiding Animal's color. After that, the base.color is used to reach "white" in Animal, whereas color reaches "black" in Dog.

C# base keyword to call the base class method

In C#, we can call the base class method using the base keyword. It is useful if base and derived classes define the same cmethod. In other words, if the method is overridden or if the derived class doesn't define the same method, there is no need to use the base keyword. Base class method can be directly called by the derived class method.

C# base keyword example to call the base class method

Let's see the simple example of a base keyword that calls the method of the base class.

Output:

eating...
eating bread...

Explanation:

In this example, we demonstrate the use of the base keyword to call a base class method from an overridden method in the derived class. Here, the Dog class overrides the eat() method, calling first the base Animal method that prints "eating...", followed by its message "eating bread…".

C# Base keyword using Constructor Chaining

In the C# programming language, when a class is inherited, the base class constructor is automatically called before the derived class constructor. The base keyword can also be explicitly utilized to call a specific constructor of the base class.

C# Base keyword example using constructor chaining

Let us take an example to illustrate the base keyword using the constructor chaining in C#.

Output:

animal...
dog...

Explanation:

In this example, we demonstrate the constructor chaining in inheritance where instantiating a Dog object initially invokes the Animal constructor, which prints "animal…", followed by the Dog constructor, which prints "dog…".

Constructors Chaining with Parameters in C#

In C#, when a base class defines a parameterized constructor, we should explicitly call the derived class to ensure proper initialization. It is accomplished by calling the parameterized base class constructor within the derived class constructor using the base keyword, followed by the respective parameters. It ensures the correct initialization of the base class with the required parameters before the execution of the derived class constructor.

C# Constructors Chaining with Parameters Example

Let us take an example to illustrate the constructor chaining with parameters in C#.

Output:

Animal constructor: Buddy
Dog constructor

Explanation:

In this example, we demonstrate the constructor chaining with parameters wherein initializing Dog("Buddy") makes an initial call to Animal's constructor through base(name) to print "Animal constructor: Buddy", followed by executing the Dog constructor to print "Dog constructor".

Difference Between base and this keyword in C#

There are several differences between the base and this keyword in C#. Some main differences are as follows:

This keyword

  • The term "this" refers to the current instance of the class where the code is being executed.
  • It allows access to members (fields, properties, and methods) of the immediate class, including any overridden or hidden members from a base class.
  • When a method is called using this.Method(), it invokes the most derived override of that method.

Base Keyword

  • The base keyword is a reference to the immediate base class of the current class.
  • It refers to members as declared in the base class, overriding any overrides or hiding in the immediate class.
  • When calling a method with base.Method(), it invokes the parent class version even if it is overridden in the derived class.

C# Example using base and this keyword

Let us take an example to illustrate the base and this keyword in C#.

Output:

Shape Area: 0
Rectangle Area (overridden): 20
Shape Area: 0
This is a Shape
This is a Rectangle

Explanation:

In this example, we have taken a Rectangle class that inherits from Shape and overrides the Area() method while hiding the PrintType() method using new. Inside the ShowInfo() method, both base and this are utilized to demonstrate how the base class methods (base.Area(), base.PrintType()) and the derived class methods (this.PrintType(), overridden Area()) can be accessed separately.

Conclusion

In conclusion, the base keyword is an object-oriented programming requirement of C# that enables a derived class to talk to its immediate base class. The "base" keyword is utilized to invoke base class constructors, access base class members and properties, and eliminate problems concerning derived members that can hide base class members. Its usage in the correct context enables cleaner inheritance hierarchies, reuse of code, and reduced confusion in member accesses in complex class hierarchies.

C# Base FAQs

1) Can we use more than one constructor in a derived class, and how do we select which base constructor to call?

Yes, we can have more than one constructor in a derived class; a different base class constructor can be called from each constructor by calling base() with the corresponding required parameters.

2) What happens if the base class lacks a public parameterless constructor?

The derived class should explicitly call a base class constructor via the base keyword, selecting among the available parameter signatures. Otherwise, it will not compile.

3) When should the base keyword be employed in methods?

Use the base keyword if we wish to call a method or property of the base class that has been overridden or hidden by the derived class.

4) Does C# allow multiple base class inheritance?

No, C# does not allow multiple class inheritance. We can inherit from only one base class, but we can inherit from several interfaces.

5) Can a base be applied to fields and properties?

Yes, a base can call fields, properties, and methods of the base class that are accessible from the derived class. It is usually applied when the derived class overshades a base class member.


Next TopicC# Polymorphism