I think this is a very trivial question but I am not able to get a definite answer to it on the net.
I have a class which contains both value types and reference types. Considering the reference types in the class will get instantiated sometime during the execution, how the memory is allocated for each member of such a class? How the pointer is stored and accessed for each of these members? Also which type is created in which memory structure, i.e. stack or heap?
I know this much that if only a variable of value type is used in my code then its value and all the other details like its type, etc are stored in the stack. Similarly if a reference type is instantiated then the actual object is created in the heap and a pointer to this memory location is stored in the stack. But what about value types present inside a class (reference type)? Where are they stored and how are they accessed?
I have given an example of such a class below. An answer in reference to this class will be very helpful.
public class Employee
{
public int EmpNo { get; set; }
public string EmpName { get; set; }
public BankAccDetails AccDetails { get; set; }
}
public class BankAccDetails
{
//Other properties here
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…