I am currently trying to construct an object which derives from a different object, but before calling the base constructor I would like to make a few argument validation.
public FuelMotorCycle(string owner) : base(owner)
{
argumentValidation(owner);
}
Now I understood that initially the base constructor is called first, is there a way I can call it only after the argumentValidation method?
The base constructor will be invoked first.
This example:
class Program
{
static void Main(string[] args)
{
var dc = new DerivedClass();
System.Console.Read();
}
}
class BaseClass
{
public BaseClass(){
System.Console.WriteLine("base");
}
}
class DerivedClass : BaseClass
{
public DerivedClass()
: base()
{
System.Console.WriteLine("derived");
}
}
will output:
base
derived
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With