You need to calculate Z before the constructor itself is called. If it is simple, you can use the built-in expression, otherwise you will need to define a helper function.
Using helper function:
public class A { public A(X x, Y y, Z z) { ... } } public class B : A { private static Z calculateZ() { } public B(X x, Y y) : base(X, Y, calculateZ()) { } }
Without helper function:
public B(X, Y) : base(X, Y, X+Y) { }
CodesInChaos
source share