What is boxing and unboxing in C#? Why does it affect performance?

Mid C#

Answer

Boxing converts a value type into an object by wrapping it inside a heap-allocated reference type.

Unboxing extracts the value type back from the object.

Boxing and unboxing are slow due to heap allocation, GC pressure, and runtime type-checking.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice