
using System;
namespace Nullable
{
class MainApp
{
static void Main(string[] args)
{
int? a = null;
Console.WriteLine(a.HasValue); // 값을 가지고 있는지 확인 (True, False)
try
{
Console.WriteLine(a.Value); // 값 출력
}
catch (Exception)
{
Console.WriteLine("a = null");
}
a = 18;
Console.WriteLine(a.HasValue);
Console.WriteLine(a.Value);
}
}
}
[실행 결과]
False
a = null
True
18
▪ 참고: Hello Fruit! - null 연산자