c# - How can I call a base class's parameterized constructor from a derived class if the derived class has no parameterized constructor? -


i have base class 2 constructors: default constructor , parameterized constructor. class inherits base class , has default constructor. how can call base class's parameterized constructor derived class?

it's not entirely clear question is, suspect either want add explicit parameterless constructor child class:

// parameterless child constructor calling parameterized base constructor public child() : base("foo", "bar") { } 

or add both parameterized , parameterless one:

public child() { }  public child(string foo, string bar) : base(foo, bar) { } 

note constructors aren't inherited - because base class has particular constructor signature doesn't mean can instantiate class using signature. child class has provide itself.

any compiler-provided parameterless constructor call parameterless constructor of base class.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -