Saturday , August 18 2018
Home / Dot Net / C# / Lesson 6: Boxing and UnBoxing in C#

Lesson 6: Boxing and UnBoxing in C#

Boxing and UnBoxing in C#:

Previously we have seen TypeCasting Now We Will see Boxing and UnBoxing in this Article.

Boxing:

Boxing is the process of converting a value type to the type object.

Or The operation of Converting a Value Type to a Reference Type is called Boxing and the reverse operation is called Unboxing.

 In boxing process, a value type is being allocated on the heap rather than the stack.

Example:

 

Output:

25

Unboxing:

Explicit conversion of same reference type back to a value type is known as unboxing.

In other Words Converting Value from object to Data type is called as Unboxing

 In unboxing process, boxed value type is unboxed from the heap and assigned to a value type which is being allocated on the stack.

Output:

25

 Back To C# Complete Tutorials

Thanks for reading this article and if you like this please share with your Friends.

Print Friendly, PDF & Email

Give us your valuable feedback

comments

About Murali

Hello everyone I am Software Developer having 3+ years of Experience in Microsoft Technologies and Others. My skills :- Asp.net, C#,Ado.net, SQL SERVER, web services, windows Service,Windows applications,HTML,CSS, JavaScript,JQuery,AnjularJs

Check Also

Remote Validation

How to Use Remote Validation in MVC

Remote Validation Attribute allows us to validate properties values with server callback using AJAX. Remote …