7/22/2010

C# Boxing and Unboxing



Boxing and Unboxing:
Conversion from value type to a reference type is called Boxing.
Conversion from reference type is called Unboxing.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BoxingAndUnboxing
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 10;
            string s = a.ToString(); //boxing
            Console.WriteLine("Boxing: " + s);

            int b = Convert.ToInt32(s); //unboxing
            Console.WriteLine("Unboxing: " + b);



        }
    }
}

No comments:

Post a Comment