Nullable and Pattern Matching
Pattern Is
An is pattern checks a value's shape and creates a typed local variable.
Pattern Is
PatternIs.cs
using System;
class Program
{
static void Main()
{
object value = ;
string result;
if (value is int number)
{
result = "int:" + (number * 2);
}
else
{
result = "other:" + value;
}
Console.WriteLine($"result={result}");
}
}
using System;
class Program
{
static void Main()
{
object value = ;
string result;
if (value is int number)
{
result = "int:" + (number * 2);
}
else
{
result = "other:" + value;
}
Console.WriteLine($"result={result}");
}
}
using System;
class Program
{
static void Main()
{
object value = ;
string result;
if (value is int number)
{
result = "int:" + (number * 2);
}
else
{
result = "other:" + value;
}
Console.WriteLine($"result={result}");
}
}
is pattern
An `is` pattern checks a value and extracts a usable variable.