What is Boxing and Un-Boxing?

Boxing: means converting value-type to reference-type.

Eg:

int I = 20;

string s = I.ToSting();

UnBoxing: means converting reference-type to value-type.

Eg:

int I = 20;

string s = I.ToString(); //Box the int

int J = Convert.ToInt32(s); //UnBox it back to an int.

Note: Performance Overheads due to boxing and unboxing as the boxing makes a copy of value type from stack and place it inside an object of type System.Object in the heap.

Comments

Popular posts from this blog

How do I calculate a MD5 hash from a string?

What is WSDL?