Are these objects's references on the Stack or on the Heap?

前端 未结 8 2085
猫巷女王i
猫巷女王i 2020-11-27 14:51

I would really appreciate if someone could tell me whether I understand it well:

class X
{
   A a1=new A(); // reference on the stack, object value on the he         


        
8条回答
  •  生来不讨喜
    2020-11-27 15:10

    I am new to C# also. Your question is very important, I also thinked of it. All documentation said, values goes stack and references goes heap, but as the guys above said, its just for the code inside methods. On stair of learning I realize that all programs code begin inside of a method which belong to an instance which belong to heap. So conceptual, the stack is not equal in term with heap like all documentation confuses people. The stack mecanism is found only in a method...

提交回复
热议问题