Login
Nederlands
About
Consulting
Projects
Resume
Contact Me!
Any fool can write code that a computer can understand.
Good programmers
write code that
humans
can
understand
.
- Martin Fowler
Boxing And Unboxing
Overview
Boxing is an implicit conversion of a value-type to the object type.
Boxing a value-type will copy the value on the heap, and place a pointer to the boxed value on the stack.
Good practice
Try to prevent boxing/unboxing when possible, use generics or multiple overloads instead.
Read
Boxing/Unboxing In .NET
for performance tests.
Examples
Boxing Operation
int
i
=
123
;
object
o
=
(
object
)
i
;
Unboxing Operation
object
o
=
123
;
int
i
=
(
int
)
o
;