class Test extends System.Object - copy or reference?

Is it absolutely correct that

class Test extends System.Object

creates a class and not a speudo-struct?

Thus, it will be passed by reference (like any class), not by copy.

When you create a pseudo-struct using extends System.ValueType it will be passed by copy.

ie, hopefully my comment at the bottom here:

is correct!

Background: Your "own" structs ... are they indeed passed by value? - Questions & Answers - Unity Discussions

If someone is certain on the answer here, thanks!

1 Answer

1

Extending from System.ValueType will always create a struct. There is no such thing as a pseudo-struct; the data will either be passed by value or by reference. That method will not change for that object during its lifetime.

Trying to create such a pseudo-struct ( public class PseudoStruct : System.ValueType ) in C# will throw the following error:

error CS0644: `PseudoStruct' cannot derive from special class `System.ValueType'

In UnityScript, that syntax is allowed, but creates a struct, as shown by the error

 BCE0107: Value types cannot declare parameter-less constructors.

When you try to have a parameterless constructor (which is not allowed for structs) in the struct.

Extending from System.Object will always create a class, which is passed by reference.

Sorry I forgot to tick this. BTW by "pseudo-struct" I was referring to that quirk in U/S. Thanks again!

–