Skip to content

Instantly share code, notes, and snippets.

@M2vH
Last active November 9, 2022 16:55
Show Gist options
  • Save M2vH/aa54114ab805bc9f5732b039f9a0f48d to your computer and use it in GitHub Desktop.
Save M2vH/aa54114ab805bc9f5732b039f9a0f48d to your computer and use it in GitHub Desktop.
using System;
int? x = 3;
if (x is int)
Console.WriteLine(x);
x = null;
if (x is null)
Console.WriteLine("x is null");

int? is a nullable type. Docs

Nullable types extend their base types to allow null values. For example, int? i = null is allowed, even though int i = null is not.

x is null is pattern matching. Docs

Pattern matching checks whether value matches a condition, and at the same time transforms it into new value(s). For example, a is int i checks that a is int, and if true produces a new value i equal to a, but typed as int.

{
"version": 1,
"target": "Run",
"mode": "Release",
"branch": "core-x64"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment