Simple Code in C# to demonstrate Boxing and unBoxing

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Postslush
{
    class TestBoxingbypostslush
    {
        public static void Main()
 {
            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();
        }
    }
}

Output :

 

Share Your Comments
Previous Simple C# Code for finding roots of Quadratic Equation
Next C# program for Break Statement

About author

Aamir Shaikh
Aamir Shaikh 1705 posts

<p>A Blogger, SEO Analyst and passionate Web Developer from India.<br /> Believes in hard work and continues working to achieve success.</p>

View all posts by this author →

You might also like