Hi Guys
NP105 reside on the Stack or Heap
ReferenceType ref1 = new ReferenceType();
ref1.X = 5;
When we defined ref1 above way, in which place ref1 reside on. That mean I wish to know whether it is reside on the Stack or Heap
Please explain.
Thank you
Fernando SotoPosted Jun 28, 2008, 9:53 PM
Posted Jun 28, 2008, 5:26 PM
Thank you for your explanation, Fernando Soto
Fernando SotoPosted Jun 28, 2008, 5:07 PM
Here is a artical you might want to read.
C# Heap(ing) Vs Stack(ing) in .NET: Part I
http://www.c-sharpcorner.com/UploadFile/rmcochran/csharp_memory01122006130034PM/csharp_memory.aspx?ArticleID=9adb0e3c-b3f6-40b5-98b5-413b6d348b91
Posted Jun 28, 2008, 4:15 PM
http://en.csharp-online.net/Value_vs_Reference
But in the above website diagram shows that ref1 is created on the Stack. It is much appreciated if you explain the reason for that.
Fernando SotoPosted Jun 28, 2008, 3:42 PM
A reference type refers to an object that is created on the managed Heap. So in answer to your question, ReferenceType ref1, will be created on the managed Heap.
Value type are created on the stack and include types as int, float, char, bool, structure and enumerations.
Fernando