Amit Kumar
How can we access base class constructor from a derived class constructor in C#?
By Amit Kumar in .NET on Sep 26 2019
  • Ravi Patel
    Oct, 2019 3

    The base keyword is used to access members of the base class from within a derived class

    A base class access is permitted only in a constructor, an instance method, or an instance property accessor.

    It is an error to use the base keyword from within a static method.

    • 2
  • Mehul Rudatala
    Nov, 2019 25

    1. using System;
    2. public class Program
    3. {
    4. public static void Main()
    5. {
    6. XYZ x = new XYZ("345");
    7. }
    8. }
    9. public abstract class ABC{
    10. public ABC(string str){
    11. Console.WriteLine("From: ABC : {0}", str);
    12. }
    13. }
    14. public class XYZ : ABC{
    15. public XYZ(string str): base("123"){
    16. Console.WriteLine("From: XYZ : {0}", str);
    17. }
    18. }

    • 0
  • Arun Kumar Tiwari
    Oct, 2019 21

    It is used to access members of the class from within derived class, Base class access only in constructor, instance method and instance property access.

    • 0
  • Arun Kumar Tiwari
    Oct, 2019 21

    It is used to access members of the class from within derived class, Base class access only in constructor, instance method and instance property access.

    • 0
  • Ishoo Anyal
    Oct, 2019 9

    YOu can use base() or if it is a parameterize constructor then you can do base(var) and so on. Base class constructor is called first when creating object of child class, it’s called constructor chaining

    • 0
  • Imran Shaikh
    Oct, 2019 9

    the base keyword is used to access the base class constructor

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS