boxing
Wrapping a value type such as an int in an object on the heap so it can be treated as an object.
In more detail
Boxing allocates memory and unboxing needs a cast, which is why pre-generic collections of object were slow and error-prone. Generics avoid it.
Related terms
- value type — A type whose variables hold the data itself, so assigning one to another copies the whole value.
- heap — The area of memory where a program stores objects whose size or lifetime is not known in advance, typically reclaimed by a garbage collector.
- generics — Types that take other types as parameters, so one definition works for many kinds of value.
- allocation — Reserving memory for a new object on the heap.
Taught in
- Collections, Generics, and LINQ — Modern .NET Core, C# & Enterprise Microservices
- Records, Pattern Matching, and Modern C# — Modern .NET Core, C# & Enterprise Microservices