Skip to content

Instantly share code, notes, and snippets.

@mpetrinidev
Created September 19, 2019 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpetrinidev/0864c22bb94df75331d6b6035a8a1106 to your computer and use it in GitHub Desktop.
Save mpetrinidev/0864c22bb94df75331d6b6035a8a1106 to your computer and use it in GitHub Desktop.
youtube-nullcoalescing-c#8
class Program
{
static void Main(string[] args)
{
static int? GetNullAge() => null;
static int? GetAge() => 27;
int? age = GetNullAge();
//Old Way
//if (age == null)
//{
// age = GetAge();
//}
//C# 7
//age = age ?? GetAge();
//C# 8.0
age ??= GetAge();
Console.WriteLine(age);
Console.ReadLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment