copy code,drag or close
The .NET compiler knows how much memory each type will need, a good example of a value type that it knows uses 8 bytes of memory is the datetime value.
When we create a variables of type DateTime, the compiler creates the information the runtime engine needs to hold that datatime in memory, in this case to allocate 8 bytes
(64-bits) of memory for the variable (data).
Each of these DateTime variables uses 8 bytes of memory.
When a programmer creates a statement like
Date1 = Date2;
The 8 bytes in Date2 are copied into the variable Date1.
Each thread has its own stack, so mulitple stacks may exist.
In each case stacks are areas of memory allocated for holding variables of type value.
Typically the variables are local varaibles or member fields declared inside a function.
When a value is passed into a method, a copy of the value is made (on the stack).
When the method is finished (out of scope) that part of the stack is free again.