Boxing and Unboxing in C sharp

Boxing is an approach of converting a value type  into a reference type.

                               int i =100;
                               object obj = i ; //Boxing

Unboxing is a process of converting a reference that is created through boxing back into a value type, but unboxing requires an explicit conversion.

                              int j = Convert.ToInt32(Obj);

           

Value Type =====> Reference Type   // Valid (Boxing)
Value Type =====>Reference Type ===>Value Type // Valid (Unboxing)
Reference Type ==> Value Type //Invalid Operation.


Note :-  You can not direct convert reference type to value type.  

3 comments:

  1. I surely acquiring more difficulties from each surprisingly more little bit of it Tyson vs Jones 2020 time

    ReplyDelete
  2. Hey, great blog, but I don’t understand how to add your site in my rss reader. Can you Help me please? แทงมวย

    ReplyDelete