Sorry for the title if it is inaccurate, I don't really know the name of what I'm looking for
Suppose I have this class:
public class Potion(){
public int WaterAmount;
public int ReagentAmount;
}
Now if I wanted a method to check the amount of water or the amount of reagent in the potion I would have:
public int GetWaterAmount ( Potion pot ){
return pot.WaterAmount;
}
public int GetReagentAmount ( Potion pot ){
return pot.ReagentAmount;
}
Now my question is how can I combine these 2 methods into one so that I can just enter the parameter of the liquid I want to check for? Here's some invalid syntax of what I was looking for:
public int GetAmount ( Potion pot, int SelectedLiquid){
return pot.SelectedLiquid;
}
void main(){
GetAmount(pot, WaterAmount);
GetAmount(pot, ReagentAmount);
}
In essence how can I make a parameter (selectedliquid) refer to different variables in a class (wateramount or reagentamount) ?
Or is this not possible and I do need to have 1 method for each variable I want to check for?