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)
HI venkat,if your saying stack and heap means, Is it computer Ram memory virtually dividing into stack and heap right?if yes then how would computer knows the scope is lost then it hasto clear value types(i.e variable and its value from stack) and alsoreference variable of reference type from stack memory implicitly?when do we use value types over reference types and what are the advantages? thanks venkat. I am waiting for reply, if there is any wrong plese correct meThanks once again for grate effort and so far every thing was very precise
Hi Venkat,Recently i have came across with your blog.Every topic which you have posted here is very precise and every one can grab the technology easily. I have one doubt both classes and interfaces are reference types and struct is a value type right? then how struct is inheriting from interface and why not it is inheriting from other classes.As per this video interface is reference type and struct is value type.while inheriting from interface its has to throw error like implicit conversion not allowed or cannot be converted form reference to value type.But we are not getting any error.Pleas look into this and above question answer me.I am in bit confusionThanks venkat grate effort.
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.