Explain the boxing and unboxing concept in .Net?

Asked 15-Nov-2017
Viewed 509 times

2

1 Answer


0

“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);
 }
}