Considering c# pointers and referencing with the following code
public class Content{
public Content(){} //empty constructor
} //end of Content class, emptiest class ever
public class Variants{
Content x;
public Variants(){ //Variants constructor
x = new Content(); //point x of this instance towards a Content object
}
} //end of Variants class
void main(){
Contents[] v = new Contents[1]; //array for storing a variable coming from a Variants object
v[0] = ((Variants)new Variants()).x; //store x of the
//instance of Variants in our single cell.
Print(typeof(v[0]))
}//end of main()
Is this a valid statement: v[0] = ((Variants)new Variants()).x;
or it will leak objects?
and
Does v[0] point to the object referenced by x? In other words, when we say Print(typeof(v[0]))
, do we imediately jump to the object referenced by x or does it imply traveling from variants object to its x variable?
If computer indeed has to travel to variants instance then to x as we mention the 0th cell (due to the way the value was stored into array), will this Print be quicker:
Variants temp = new Variants()
Contents cTemp = temp.x; //reference variable to point directly at x
v[0] = cTemp; //feed in this pointer, not Variants.x instruction
Print(typeof(v[0]))