boxing

What is boxing and unboxing?
http://msdn.microsoft.com/msdnmag/issues/1200/dotnet/

Advantage?
To convert a value type to reference type

Disadvantage?
Performance

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;
or
System.Int32 i =10;
Ans:Both will generate the same IL code

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s


%d bloggers like this: