What is boxing and unboxing?

To convert a value type to reference type


Best practice:
int i = 10;
Console.Writeline(“i = ” + i + ” ” + i);
Writeline invokes String Concat(object arg1, object arg2) method to generate the string to be passed on to Writeline method.
Now here when passing the value of i boxing happens. If there is a reptead use of a variable in the Writeline statement it can explicitly boxed and then passed on to the Writeline function.

Which is faster?
int i =10;
System.Int32 i =10;
Ans:Both will generate the same IL code


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: