Suppose we have the following code:
void method() {
int[] test = new int[3];
test[0] = 0;
test[1] = 1;
test[2] = 2;
}
From what I read from Jon Skeet's post on SO, the new int[3]
part is equivalent to:
public class ArrayInt3 {
public readonly int length = 3;
public int value0;
public int value1;
public int value2;
}
So does that mean test
(a reference to ArrayInt3
) is on the stack? And does that mean ArrayInt3
is on the heap? And I suppose value0
, value1
, and value2
are on the heap as well (i.e. 0, 1, 2 in this example)?
So in total, there is 4 objects on the heap, correct?