C# Boxing & Unboxing Tutorial with Examples
Today, We want to share with you C# Boxing & Unboxing Tutorial with Examples.
In this post we will show you Boxing and Unboxing in C#.NET, hear for C# boxing and unboxing we will give you demo and example for implement.
In this post, we will learn about Understanding Boxing and Unboxing in C# with an example.
Boxing and Unboxing in C#
In this post,We will learn about Boxing and Unboxing in C# with an example.
Now in this post, I will explain about Boxing and Unboxing in C# with appropriate example. Many time knowingly or unknowingly we use these concepts and it can have disastrous performance issues in application. So in this article we will see what is boxing and unboxing and how does it cause performance problem and how to use them carefully to avoid these issues.
So let us start with boxing and below are some points and definitions around it.
- It is a process of converting value type to the referenced type.
- Value type variables are stored in Stack Memory
[php]static void Main(string args)
int count = 10; // Step 1 Declare count of integer datatype.
object obj; // Step 2 :- Declaration of Object obj.
obj = count; // ß Step 3 :- Boxing happens here .Assigning value of count to object obj.
- Unboxing is a process of converting reference type to the value type.
- Referenced Type variables are stored in Heap Memory.
static void Main(string args)
int count = 10; // Declaration and Initialisation of Variable count of integer datatype.
object obj; // Declaration of Object obj.
obj = count; // Boxing
int j = (int)obj; // Unboxing
I hope you get an idea about Introduction To C# boxing and unboxing.
I would like to have feedback on my Infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.