Coding Lab - TechOnTechnology

Program in C# to demonstrate boxing and unBoxing.

using System;

namespace Lab_Ex_4
{
    class TestBoxing
    {
        public static void Main()
1.  {
            int i = 123;
            object obj = i;  // Implicit boxing

            Console.WriteLine("\nThe value-type value = {0}", i);
            Console.WriteLine("\nThe object-type value = {0}", obj);
            Console.ReadLine();
            i = 456;       // Change the contents of i  
            Console.WriteLine("\nThe value-type value = {0}", i);
            Console.WriteLine("\nThe object-type value = {0}", obj);
            Console.ReadLine();

            int j = (int)obj;
            Console.WriteLine("\nThe value-type value = {0}", j);
            Console.ReadLine();
        }
    }
}

Name

Email *

Message *