In this paper, a simple example of the implementation of C # Boxing and unboxing operations, simple boxing is to convert a value type to a reference type, unboxing is to convert the reference type to a value type, is involved in the use of stacks and heaps of things, the people who have learned C # should know, so here is not shiver, this example code is also for C # Beginner's, very simple.
The specific implementation code is as follows:
Using system;using system.collections.generic;using system.linq;using system.text;namespace UnBoxing{ class Program { static void Main (string[] args) { int i = 123;//declares a variable i of type int and initializes to 123 object obj = i; Execute boxing Operation Console.WriteLine ("Boxing operation: value {0}, after boxing object is {1}", I, obj); int j = (int) obj;//perform the unboxing Operation Console.WriteLine ("Unboxing: Boxed object is {0} with a value of {1}", obj, j); Console.ReadLine ();}}}