Part 29 - C# Tutorial - Difference between classes and structs in C#
Free C#, .Net and Sql server video tutorial for beginners and intermediate programmers.
Subscribe to:
Post Comments (Atom)
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)
ReplyDeleteYou 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.
Delete1. 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.
ReplyDeleteIf 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)