Copying semantics of boxing and unboxing - CSharp Custom Type

CSharp examples for Custom Type:Box Unbox

Introduction

Boxing copies the value-type instance into the new object, and unboxing copies the contents of the object back into a value-type instance.

In the following example, changing the value of i doesn't change its previously boxed copy:

int i = 3;
object boxed = i;
i = 5;
Console.WriteLine (boxed);    // 3

Related Tutorials