- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Boxing and Unboxing in C#
Boxing
Boxing is the implicit conversion of a value type to a reference type.
Unboxing
Unboxing is the explicit conversion of the reference type created by boxing, back to a value type.
Example
Let us see an example code snippet −
// int int myVal = 12; // Boxing object myBoxed = myVal; // Unboxing int myUnBoxed = (int) myBoxed;
Let us see another example that shows an array list in C# −
int a = 5; ArrayList arr = new ArrayList(); // Boxing arr.Add(a); // UnBoxing int b = (int)arr[0];
Advertisements