Reputation: 3490
If the base class and derived class both have their constructors with parameters then where we pass the parameters to the base class constructors?
Upvotes: 24
Views: 51553
Reputation: 176
public class DerivedClass(object param): BaseClass(param){// in .net core 8}
Upvotes: 1
Reputation: 61349
Like this:
public class DerivedClass : BaseClass
{
public DerivedClass(int derivedParam, String baseParam):base(baseParam)
{
}
}
The base
keyword here calls the base class constructor that matches the provided parameter overload.
Upvotes: 64