|
1
|
|
|
2
|
- value types
- variables contain their own data directly
- local variables always live on the stack
- reference types
- variables refer to their data indirectly
- local variables refer to objects on the heap
|
|
3
|
|
|
4
|
- everything implicitly inherits from object
- arrays, classes, interfaces, delegates
- structs, enums, as well!
|
|
5
|
|
|
6
|
- when a reference variable binds to a value
- the runtime copies the value onto the heap
- the reference refers to the copy on the heap
- this is called boxing
|
|
7
|
- unboxing copies the boxed value back again
- this requires an explicit cast to the exact type
- If the reference is null - NullReferenceException
- if the target type is wrong - InvalidCastException
|
|
8
|
- boxing creates a unified type system
|
|
9
|
- in fact, value types do not derive from object
- each value type has a hidden wrapper type
- the wrapper type holds the boxed value
- object virtual methods aren't overridden in values
- they are overridden in the wrapper type
|
|
10
|
|