Call constructor in base class : Base Class « Class « C# / CSharp Tutorial






using System;

public class BaseClass
{
    public BaseClass(int x)
    {
        this.x = x;
    }
    public int X
    {
        get
        {
            return(x);
        }
    }
    int    x;
}

public class Derived: BaseClass
{
    public Derived(int x): base(x)
    {
    }
}

class MainClass
{
    public static void Main()
    {
        Derived d = new Derived(15);
        Console.WriteLine("X = {0}", d.X);
    }
}
X = 15








7.22.Base Class
7.22.1.Add constructors to base class
7.22.2.Add more constructors to base class
7.22.3.Pass a derived class reference to a base class reference.
7.22.4.Call constructor in base class
7.22.5.Define base class another cs file