Muhammad Mubashar’s Post

View profile for Muhammad Mubashar, graphic

Principal Software Engineer, Simplifying Complexity

What is Boxing in C#? In C# boxing is a process by which a value type (e.g., int, float, struct) is implicitly converted into an object reference type (e.g., object). This conversion is performed when a value type needs to be treated as an object, such as when it's stored in a collection that requires objects, like ArrayList, or passed as a parameter to a method that accepts objects. Boxing is a computationally expensive process. When boxing, the following steps are involved: Allocate memory: A new memory location is allocated on the managed heap to store the boxed value. Copy value: The value of the value type variable is copied to the newly allocated memory location. Wrap in object: The newly allocated memory location is then treated as an instance of the object type. #csharp #boxing #dev #dotnet #performance

  • No alternative text description for this image

To view or add a comment, sign in

Explore topics