Suppose I have this code:
struct Normal
{
public float x;
public float y;
}
class NormalContainer
{
public Normal[] Normals
{
get; set;
}
}
class Main
{
void Run( NormalContainer container )
{
Normal[] normals = container.Normals // 1 - see below
normals[5].x = 4; // 3 - see below
container.Normals = normals; // 2 - see below
}
}
Does (1) create a copy of the array or is this a reference to the memory occupied by the array? What about (2) ?
Thanks
(1) copies the array’s reference
(2) same
Array variables are reference types, regardless of their underlying element type, so whenever you assign an array variable to another, you are just copying the reference.