这是我想做的:
public class Worker
{
public int wage;
public void pay()
{
Economy.money -= this.wage;
// I want the money(of the economy) to be subtracted by the wage of the worker.
}
}
public class Economy
{
public int money;
}
如果我可以拥有不止一种经济,那我会喜欢的。
因此,我希望将工人的工资减去经济收入(工人所属的货币)。
我该怎么做呢?
如果您想要多个经济体,那么您需要一个可跟踪每个工人所属经济体的资产。然后,您可以使用该引用从正确的经济中减去工资:
public class Worker {
public Economy InEconomy { get; private set; }
public int Wage { get; private set; }
// set the econdomy and wage in the constructor
public Worker(Economy economy, int wage) {
this.Wage = wage;
this.InEconomy = economy;
}
public void Pay() {
InEconomy.money -= this.Wage;
}
}
public class Economy {
public int money;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句