Nullable and Pattern Matching
Nullable Value Types
A nullable value type can hold a normal value or null.
Nullable Value Types
NullableValueTypes.cs
using System;
class Program
{
static void Main()
{
int? score = ;
bool hasScore = score.HasValue;
int shown = score.GetValueOrDefault();
Console.WriteLine($"hasScore={hasScore}");
Console.WriteLine($"shown={shown}");
}
}
using System;
class Program
{
static void Main()
{
int? score = ;
bool hasScore = score.HasValue;
int shown = score.GetValueOrDefault();
Console.WriteLine($"hasScore={hasScore}");
Console.WriteLine($"shown={shown}");
}
}
using System;
class Program
{
static void Main()
{
int? score = ;
bool hasScore = score.HasValue;
int shown = score.GetValueOrDefault();
Console.WriteLine($"hasScore={hasScore}");
Console.WriteLine($"shown={shown}");
}
}
nullable value
A nullable value type uses `?`, such as `int?`, to allow `null`.