Consider having the following code:
public class TheBase { public int One { get; set; } public int Two { get; set; } public int Three { get; set; } } public class Derived : TheBase { public Derived(TheBase theBase) { One = theBase.One; Two = theBase.Two; Three = theBase.Three; } public int Four { get; set; } public int Five { get; set; } }
Is there an easier way to pass the properties "One", "Two" and "Three" from the base class, to the derived class? Is there some kind of a neat hack available, or this is the best optimal solution for such a problem?
This is the proper implementation:
public class TheBase
{
public int One { get; set; }
public int Two { get; set; }
public int Three { get; set; }
public TheBase(int one, int two, int three)
{
One = one;
Two = two;
Three = three;
}
public TheBase(TheBase theBase)
{
One = theBase.One;
Two = theBase.Two;
Three = theBase.Three;
}
}
public class Derived : TheBase
{
public int Four { get; set; }
public int Five { get; set; }
public Derived(TheBase theBase, int four, int five) : base(theBase)
{
Four = four;
Five = five;
}
public Derived(int one, int two, int three, int four, int five) : base(one, two, three)
{
Four = four;
Five = five;
}
}
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