Interviews - C# Corner

Syed Shujaat Hasnain Abdi
What is the Boxing and Unboxing?
By Syed Shujaat Hasnain Abdi in .NET onMar 26 2016
  • Syed Shujaat Hasnain Abdi
    Mar, 2016 26

    Boxing and unboxing is the practise of converting a value type to the type object or to any interface type implemented by this value type. Boxing is implicit and unboxing is Explicit.We will describe implicit and explicit later..Boxing: it is a CLR (common language runtime) process and that’s why it’s called implicit, actually when CLR box a Value Type into Object Type is called boxing.Unboxing: when we extract value type from the Object is called Unboxing and we have to cast it explicitly as it shows in illustration below.Fox Example BoxingInt c=500; // the following line will boxes c into object Object o=c;When the above line will executes CLR create objects instance on managed heap and assign value of c to o.Unboxing:o=500; c=(int)o;as we can see we need to implicitly cast o (i.e System.object type) into c that is Value Type

    • 0

Most Popular Companies

Most Popular Job Functions

MOST LIKED QUESTIONS