Search code examples
c#referencexnatexture2d

(Texture2D) t1 = t2; Does it creates reference or a copy?


Quick question. (I was not able to find documentation about this anywhere)

When you do this:

Texture2D t1;
t1 = content.Load<Texture2D>("some texture");

Texture2D t2;
t2 = t1;

Does it creates a reference or actually copies the texture?

I would like to know it so I can take it into account when implementing related stuff.


Solution

  • Texture2D is a class. Hence, assignment will create a copy of the reference - t1 and t2 will have referential equality, ie Object.ReferenceEquals(t1, t2) will be true.