If I instantiate an object like:
public class Program
{
public static PlayerShip mainShip = new PlayerShip();
}
And then in another class I do:
public class RandomEncounters
{
var subShip = new PlayerShip();
public void PlayEncounter()
{
subShip = Program.mainShip;
}
}
My understanding is that both subShip
and mainShip
are now referencing the same object in the 'heap' or memory. Is this correct, and also, is this a bad idea?
My understanding is that both subShip and mainShip are now referencing the same object in the 'heap' or memory.
If PlayerShip
is a class
then yes, you will have two references for the same object.
If PlayerShip
is a struct
then no, assignment will a create a copy and will use that copy.
is this a bad idea
That's neither bad nor good, that's just a tool.
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