C# Type System
C# Type System Contains Three Types :
- Value Types
- Reference Types
- Pointer Types
- When we convert Value Type to Reference Type is called Boxing.
- When we convert Reference Type to Value Type is called Un-boxing.
Example : Boxing
Int value =12 ;
Integer Type Of Variable
Object obj= value ; //Boxing
The first line I have created a Value Type
integer variable (Value) and assigned a value.
2- In the Example :
The second line I have created and instance
of Object class and assign the value of integer
variable (value) to obj.
In this example we converted Value Type In to Reference type .This type of operation called Boxing.
Example : UnBoxing
1-In the Example :
2- In the Example :
Example : UnBoxing
int value=20;
Object obj=value ; //Boxing
int val1=(int)obj; //UnBoxing
The first line I have created a Value Type integer variable (Value) and assigned a value 20 .
2- In the Example :
The second line I have created and instance of Object class and assign the value of integer variable (value) to obj. Called Boxing
3. In third line shows extracts the value type from the object. This is converting a value of a reference type into a value type. This is called UnBoxing
3. In third line shows extracts the value type from the object. This is converting a value of a reference type into a value type. This is called UnBoxing
In this example we converted Reference type In to Value Type .This type of operation called UNBoxing.
No comments:
Post a Comment