Hi Team,
Today i will explain Boxing and Unboxing in C#.
C# Type system mainly divided into 3 parts:-
1. Value Type
2. Reference Type
3. Pointer Type
bool,byte,char,decimal,double,float,int,long,short are the value types
struct ,Class and object are reference type
Converting a value type to reference type is known as boxing and reference to value type is known as unboxing.
I will show it with the help of example below :-
//Boxing Example
int x = 1;
object obj = x;
//Unboxing Example
int y = (int)obj;
To explore more you can take reference from here :-
https://msdn.microsoft.com/en-us/library/ms173104.aspx
Thanks
0 Comment(s)