In C# there you have "reference types" and "value types". Reference types are created with the class
keyword. Value types are created with the struct
keyword. (Extended explanation on MSDN.)
A reference (for example a "Planet myPlanet
" variable if you have class Planet
) is very similar to a pointer. It takes the same space (32 bits or 64 bits, depending on your architecture) and "points to" (references) an instance of a reference type. Unlike pointers you can't perform arithmetic on them, and this is so the garbage collector can do its thing and track what objects are still referenced (so they are not collected).
So you are quite safe to set the UserData
to an instance of the planet object. It will refer to that same object and a copy will not be made.
It's a different story if you have a value type (ie: struct Planet
). This would get copied when you assign it. (Actually, in this case, because UserData
is of type object
and expects a reference type - the framework will "box" your value type by copying it into an immutable reference type.)
Personally I find it helpful - especially when doing game development where you care about memory - to use different syntax highlighting colours for reference types vs value types.