I have a script that manages different types of tiles, all info of a tile is grouped together in a struct "TileInfo". Now I have a method:
Now my question, will this return a copy of that struct, or the actual struct itself ? So when I use this method, and change the returned struct, will the original change ? If so, how do I return a copy so my original struct stays the way he was ? If not, just out of curiosity, how do I make it so it returns the actual struct ? :P (I need it to return a copy, but it's still interesting :P)
(I'm not sure if I'm saying it right "returning the actual struct", or is there a word for an instance of that struct (like "object" when we're talking about classes) or is it also just called an "object" ? :D)
asked Apr 08 '11 at 11:48 AM
structs are value types. As such the function will return a copy of that struct and NOT the actual struct itself.
See http://msdn.microsoft.com/en-us/library/s1ax56ch.aspx for more info.
answered Apr 08 '11 at 01:31 PM
Structs are always copied, classes are always referenced
answered Apr 08 '11 at 01:45 PM