I have this container class:
class Fruit
{
public Apple apple;
public Banana banana;
}
And I have a function in another class that looks like this:
public void ChangeFruit(Fruit fruit)
{
fruit.apple = memberApple;
fruit.banana = memberBanana;
}
And that works fine.
However, I want to know why this doesn't work:
If I change the ChangeFruit method to instead of taking the container, to take the actual fruit classes, like this:
public void ChangeFruit(Apple apple, Banana banana)
{
apple = memberApple;
banana = memberBanana;
}
Then this does not work unless the ref keyword is passed with each argument. Why do I need the ref keyword here and not there?
By the way, when calling the latter ChangeFruit, I call it like this:
ChangeFruit(myFruit.apple, myFruit.banana);
As opposed to ChangeFruit(myFruit);
I just want to know when passing the container class I don't need the ref keyword but when I pass each fruit individually I do. Either way I am passing myFruit, except in the latter example I just pass its member variables individually instead of the entire container.