oopcastingtype-conversionboxing

Upcasting and down-casting is also boxing and unboxing?


I'm new to OOP and I have a question about these concept Do the upcasting and down-casting and boxing and unboxing have the same meaning is C#? Upcasting and down-casting is also boxing and unboxing?


Solution

  • Boxing/unboxing is kind a special case of type casting.

    Boxing is the process of converting a value type to the type object or to any interface type implemented by this value type.

    Boxing does allocate additional memory as a new reference type is created. Also, boxing process needs the value to be not nullable.

    So as you see, boxing is more specific process comparing to type casting, and still they share similar nature.