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.
using System;public class Program{ public static void Main() { XYZ x = new XYZ("345"); }}public abstract class ABC{ public ABC(string str){ Console.WriteLine("From: ABC : {0}", str); }}public class XYZ : ABC{ public XYZ(string str): base("123"){ Console.WriteLine("From: XYZ : {0}", str); }}
using System;
public class Program
{
public static void Main()
XYZ x = new XYZ("345");
}
public abstract class ABC{
public ABC(string str){
Console.WriteLine("From: ABC : {0}", str);
public class XYZ : ABC{
public XYZ(string str): base("123"){
Console.WriteLine("From: XYZ : {0}", str);
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.
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
base()
base(var)
the base keyword is used to access the base class constructor