
using System;
namespace Object
{
class Program
{
static void Main(string[] args)
{
object a = 123;
object b = 3.14m;
object c = true;
object d = "Hello World!";
Console.WriteLine($"{a}\n{b}\n{c}\n{d}");
}
}
}
[실행 결과]
123
3.14
True
Hello World!
using System;
namespace BoxingUnboxing
{
class MainApp
{
static void Main(string[] args)
{
int a = 123;
object b = (int)a; // 박싱 (힙에 저장)
int c = (int)b; // 언박싱 (스택에 저장)
Console.WriteLine($"{a}\n{b}\n{c}");
}
}
}
[실행 결과]
123
123
123
▪ 사진 출처: Pixabay - Mediamodifier