call base class constructor from derived class c# code example
Example 1: c# superclass constructor
public Vehicle( double speed )
{
Speed = speed;
LicensePlate = Tools.GenerateLicensePlate();
}
class Sedan
{
public Sedan(double speed)
{
Speed = speed;
LicensePlate = Tools.GenerateLicensePlate();
Wheels = 4;
}
class Sedan : Vehicle
{
public Sedan(double speed) : base(speed)
{
Wheels = 4;
}
}
Example 2: how to get derived class from base class C#
class Base {
[...]
}
class Derived : Base {
[...]
}
Base baseInstance = new Derived();
Derived derivedFromInstance = (Derived)baseInstance;