Boxing is a process to convert value type to reference type and Unboxing is a process to convert Reference type to value type.
Output:
Source code of Boxing and Unboxing:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Program obj = new Program();
obj.Boxing_UnBoxing_Example();
Console.ReadLine();
}
private void Boxing_UnBoxing_Example()
{
int i = 123;
//Boxing Example
object b = i;
Console.WriteLine("Boxing Value: " + b);
//Unboxing Example
int j = (int)b;
Console.WriteLine("UnBoxing Value: " + j);
}
}
}
0 comments:
Post a Comment