rockstar - value vs reference Flashcards
1
Q
Value types - Allocation
A
- Allocated on the stack
- When you declare a value type variable, data is stored directly in memory where the variable is created
2
Q
Value types - Passing to methods
A
- Passes copy of data
- Changes to value within the method does not affect original variable
3
Q
Reference Types - Allocation
A
- Allocated on the heap
- When you declare a reference type variable, a reference (memory address) to the actual data is stored on the heap
4
Q
Reference Types - Passing to methods
A
- Passes reference address
- Changes to variable will change the original value because it references the same memory location in the method