as we know reference types are always stored on heap and value types are in stack memory.
e.g.
public Class A{
public int myInt=10;
public void Display(){
}
}
here, if i create object of class A it goes in heap and myInt goes in stack right..?
now, how class object (heap) interact with myInt public variable (stack)?
can anybody please explain it..
Ask yourself: which part of the reference type is stored on the heap? What kind of memory? What does the reference type consist of?
– Primarily, it consists of the memory of its member variables.1) These are the data that is stored on the heap. So in your example, that would be the
myIntvariable.Value types are only stored on the stack (as you assumed) if they are local variables inside a method, or their parameters. This is what the stack is there for: storing local variables and parameters (and the return pointers of function calls).
1) And also sometimes a so-called vtable which stores the addresses of virtual functions. But this is irrelevant for this question.