MaxRecursion MaxRecursion - 10 months ago 360
C# Question

Boxing and Unboxing

I have a small doubt regarding Boxing and Unboxing in C#.

int i=1;
System.Int32 j = i;

above code can be called as boxing?

Answer Source

No, that's not boxing at all. int is just an alias for System.Int32. That code is equivalent to:

int i = 1;
int j = i;

For boxing to occur, there has to be a conversion to a reference type, e.g.

int i = 1;
object j = i;


int i = 1;
IComparable j = i;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download