MaxRecursion MaxRecursion - 1 month ago 235
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;