As
the name suggests UnBoxing is the
reverse of Boxing. In Boxing we saw that a value type gets converted into a
reference type, UnBoxing is conversion of the reference type back to a value
type.
We will continue with our example which we used for Boxing and implement UnBoxing by adding one more line of code to explain UnBoxing.
int nAge = 10;
Object objAge = nAge; // Boxing occurs here.
int nUnBoxedAge = (int)objAge; //UnBoxing occurs here.
In line 3 of the above example the object objAge which is a reference type is converted to a value type int.
We will continue with our example which we used for Boxing and implement UnBoxing by adding one more line of code to explain UnBoxing.
int nAge = 10;
Object objAge = nAge; // Boxing occurs here.
int nUnBoxedAge = (int)objAge; //UnBoxing occurs here.
In line 3 of the above example the object objAge which is a reference type is converted to a value type int.
No comments:
Post a Comment