c# call parent constructor code example
Example 1: C# call constructor within another
public Sample(string str) : this(int.Parse(str)) { }
Example 2: 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 3: c# call base constructor
public class MyExceptionClass : Exception
{
public MyExceptionClass(string message, string extrainfo) : base(message)
{
}
}