boxing and unboxing in C#

 

Write a program to demonstrate the boxing and unboxing.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace ConsoleApplication5

{

 

classProgram

{

staticvoid Main(string[] args)

{

int i = 123;                  // Boxing copies the value of i into object o.

object o = i;          // Change the value of i.

 

i = 456;          // the change in i does not effect the value stored in o.

 

System.Console.WriteLine("The value-type value = {0}", i);

 

System.Console.WriteLine("The object-type value = {0}", o);

Console.ReadLine();

}

}

}
Output:

Comments

Popular posts from this blog

simple program C#

Regular Expression Validator Control in asp.net

two dimension array in C#