7. boxing or unboxing in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace boxingunboxing.cs
{
class Program
{
static void Main(string[] args)
{
int a = 22;
object ans = a; // boxing (valuetype to referncetype)
Console.WriteLine(ans);
object no = 23;
int no2;
no2 = Convert.ToInt16(no); // unboxing (referncetype to valuetype)
Console.WriteLine(no2);
Console.Read();
}
}
}
Comments
Post a Comment