Boxing and Unboxing
Demo on Boxing and Unboxing
Boxing: Converting value type to Reference type is called Boxing.
UnBoxing: Converting Reference type to value Type is called UnBoxing.
Program:
using System;
namespace FreshersLike
{
class BoxingNUnboxingDemo
{
public static void Main()
{
int i = 10; //Value Type Member
object o; //Reference Type Member
o = i; //Boxing
int j; //Value Type Member
// j = o; Error
j = (int)o; //Unboxing
int k; //Value Type Member
k = i; //Assignment
Console.WriteLine("{0} , {1} , {2} , {3} ", i,j,k,o);
}
}
}
0 comments:
Post a Comment