Explain the boxing and unboxing concept in .Net?

2 votes
155 views
Tarun Gautam asked 15-Nov-2017 in programming by Tarun Gautam

Explain the boxing and unboxing concept in .Net?

1 Answer

0 votes
Arti Mishra answered 19-Sep-2018 by Arti Mishra

“Boxing and Unboxing concept in .NET” 

In a .NET programming language, convert the value type to reference type is called boxing concept. But the unboxing concept is just opposite to the boxing concept, it converts the reference type to its value type. The main difference between boxing and unboxing concept is, boxing concept convert the value explicit but unboxing concept converts the reference type to implicit.

Explain the boxing and unboxing concept in .Net?

For Example:
class Test
{
 static void Main() {
  int i = 5;
  object obj = i;      // boxing
  int j = (int) obj;      // unboxing
Console.WriteLine(“Boxing Value : ”+i);
Console.WriteLine(“Unboxing Value : ”+j);
 }
}