---
title: "What is the significance of the \"base\" keyword in C# and how is it used in inheritance?"  
description: "What is the significance of the \"base\" keyword in C# and how is it used in inheritance?"  
author: "Utpal Vishwas"  
published: 2023-07-02  
updated: 2023-07-04  
canonical: https://www.mindstick.com/forum/158928/what-is-the-significance-of-the-base-keyword-in-c-sharp-and-how-is-it-used-in-inheritance  
category: "oops"  
tags: ["c#", "oops", "inheritance"]  
reading_time: 2 minutes  

---

# What is the significance of the "base" keyword in C# and how is it used in inheritance?

What is the significance of the "[base](https://www.mindstick.com/articles/12627/how-can-predictive-analytics-enhance-customer-base-and-experience)" [keyword in C#](https://www.mindstick.com/forum/253/difference-between-ref-and-out-keyword-in-c-sharp) and how is it used in [inheritance](https://www.mindstick.com/articles/13095/inheritance-and-its-types)?

## Replies

### Reply by Aryan Kumar

In C#, the `base` [keyword](https://www.mindstick.com/forum/33572/sql-inner-join-keyword) is used to access members of the base class from within a derived class. It can be used to:

- Call a method on the base class that has been overridden by another method.
- Specify which base-class constructor should be called when creating instances of the derived class.

For example, consider the following code:

C#

```plaintext
class BaseClass
{
    public void BaseMethod()
    {
        Console.WriteLine("This is the BaseMethod() method.");
    }
}

class DerivedClass : BaseClass
{
    public override void BaseMethod()
    {
        Console.WriteLine("This is the DerivedClass.BaseMethod() method.");
    }
}

class MainClass
{
    public static void Main()
    {
        DerivedClass derivedClass = new DerivedClass();
        derivedClass.BaseMethod();
    }
}
```

In this code, the `BaseMethod()` method is overridden in the `DerivedClass` class. When the `BaseMethod()` method is called on the `derivedClass` object, the overridden version of the method is executed. However, if we want to call the original version of the `BaseMethod()` method, we can use the `base` keyword. For example:

C#

```plaintext
derivedClass.BaseMethod(); // Calls the overridden version of the method
base.BaseMethod(); // Calls the original version of the method
```

The `base` keyword can also be used to specify which base-class constructor should be called when creating instances of the derived class. For example:

C#

```plaintext
class BaseClass
{
    public BaseClass()
    {
        Console.WriteLine("This is the BaseClass() constructor.");
    }
}

class DerivedClass : BaseClass
{
    public DerivedClass()
    {
        Console.WriteLine("This is the DerivedClass() constructor.");
    }
}

class MainClass
{
    public static void Main()
    {
        DerivedClass derivedClass = new DerivedClass(); // Calls the DerivedClass() constructor
        derivedClass = new DerivedClass(10); // Calls the BaseClass() constructor
    }
}
```

In this code, the `DerivedClass` class has two constructors. The default constructor calls the `BaseClass` constructor, and the parameterized constructor does not call the `BaseClass` constructor. When we create a `DerivedClass` object without passing any parameters, the default constructor is called. However, if we pass a parameter to the `DerivedClass` constructor, the parameterized constructor is called, and the `BaseClass` constructor is not called.

The `base` keyword is a powerful tool that can be used to access members of the base class from within a derived class. It can be used to call methods, specify constructors, and more.


---

Original Source: https://www.mindstick.com/forum/158928/what-is-the-significance-of-the-base-keyword-in-c-sharp-and-how-is-it-used-in-inheritance

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
