Home » .Net

What is boxing and unboxing in C#?

Learn: What is boxing and unboxing in C#.Net with definitions, declaration and Example?

There are 2 types in c# one is value type and other is reference type. Object is the base class of all the types in C#.

When a value type is converted into object type then this implicitly conversion process is called boxing. On the other hand when an object type is converted back to its value type explicitly then it is called as unboxing.

Example:

int a = 10;
// Here value of variable a is boxed and assigned into variable o;
object o = a; 

The value of object o need to be unboxed at time of retrieval.

int a =(int)o;

An explicit conversion is required while unboxing process.

boxing and unboxing in C#.Net
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.