Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Implementing Boxing and Unboxing in .Net 2.0.

Author: DevAsp Team
Download Source Code : 699_Boxing UnBoxing.zip

In this article you will leaning that how you can implement boxing and unboxing in .net 2.0 using c#.

Boxing is conversion of value type to reference type.

 

And its simplest example is following

 

using System;

using System.Collections.Generic;

using System.Text;

 

namespace ConsoleApplication3

{

    class Program

    {

        static void Main(string[] args)

        {

//Intger

            int _intvalue = 15;

// object type

            Object _Obj=200;

                        //Boxing

            _Obj = (Object)_intvalue;

            System.Console.WriteLine(_Obj);

            System.Console.Read();          

        }

    }

}

 

Unboxing is conversion of reference type to value type. This is reverse of Boxing.

 

And its simplest example is following

using System;

using System.Collections.Generic;

using System.Text;

 

namespace ConsoleApplication3

{

    class Program

    {

        static void Main(string[] args)

        {

                        //Intger

            int _intvalue = 15;

                        // object type

            Object _Obj=200;

//UnBoxing

            _intvalue = (int)_Obj;

            System.Console.WriteLine(_intvalue);

                      

        }

    }

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Create your Own Timer using System.Threading NameSpace in .NET 2.0 using C#.

Disclaimer - Privacy
© 2002-2017 DevASP.net