Free C#, .Net and Sql server video tutorial for beginners and intermediate programmers.
Is it right to infer that elements on the stack is gets cleared on its own when the scope of the element is lost (value types) vs elements on the heap needs to be cleared by the garbage collector? Also how does a struct look like on a stack (i beleive its objects as well as object variable both are stored on stack only)
You are right priyanaka. and to the 2nd part, yes, struct's variable and it's values are both stored on the stack and gets cleared, when the scope is lost.
1. ID is an int type in 'Customer' class, since int is a value-type it shall store it on stack memory, rather heap memory. I'm bit confused in this context.If int ID stores on Heap Memory, then we can say value type can store on heap.2. Struct shall value type, on assuming there is a string variable defined in struct type, so this variable should store it on 'heap' memory since string is ref type. I shall want to know in this case string shall save in stack memory(bcoz it is present in struct) or heap memory (since string is ref type)
If you like this website, please share with your friends on facebook and Google+ and recommend us on google using the g+1 button on the top right hand corner.