
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How to explicitly call base class constructor from child class in C#?
Make use of this keyword in c# to call one constructor from another constructor To call a constructor which is present in parent class make use of base keyword
Example
To call a constructor which is present in another class make use of base keyword
class DemoBase{ public DemoBase(int firstNumber, int secondNumber, int thirdNumber){ System.Console.WriteLine("Base class Constructor"); System.Console.WriteLine($"{firstNumber} {secondNumber} {thirdNumber}"); } } class Demo : DemoBase{ public Demo(int firstNumber, int secondNumber, int thirdNumber) : base(firstNumber, secondNumber, thirdNumber){ System.Console.WriteLine("Derived class Constructor"); System.Console.WriteLine($"{firstNumber} {secondNumber} {thirdNumber}"); } } class Program{ static void Main(){ Demo obj = new Demo(1, 2, 3); Console.ReadLine(); } }
Output
Base class Constructor 1 2 3 Derived class Constructor 1 2 3
- Related Articles
- How to call parent constructor in child class in PHP?
- How to call a parent method from a child class in JavaScript?
- How to call the constructor of a parent class in JavaScript?
- How can we call one constructor from another in the same class in C#?
- How to call a parent class function from derived class function in C++?
- How to ensure that child class overrides a super class method in java?
- How to call one constructor from another in Java?
- How to call the constructor of a superclass from a constructor in java?
- What happens if we call "super()" in a constructor without extending any class, in java?
- How to call a method of a class in C#
- How base-class is defined in Swift?
- How to call Private Constructor in Java
- Virtual base class in C++
- The :last-child Pseudo-class in CSS
- The :first-child Pseudo-class in CSS

Advertisements