Boxing :- is Converting Value type to Reference type.
Unboxing :- is Converting Reference type to Value type
Example on Boxing and UnBoxing
namespace Boxing_vs_Unboxing
{
class Program
{
static void Main(string[] args)
{
int i = 1;
object obj = i;//Boxing
Console.WriteLine(obj.ToString());
int j = (int)obj;//Unboxing
Console.WriteLine(i.ToString());
Console.Read();
}
}
}
No comments:
Post a Comment