using System.Collections.Generic;
public static void Main()
var listOfThings = new List<string> { "String one" };
if (listOfThings?.Count != 0)
Console.WriteLine("Not null and has items");
if (listOfThings?.Count != 0)
Console.WriteLine("This check will give you a false positive since a null object has no count.");
Console.WriteLine("If you then assume there are items and try to operate on listOfThings, you will get a NullReferenceException.");
if (listOfThings is null || listOfThings.Count == 0)
Console.WriteLine("Null or empty with correct check using pre C# 9 syntax.");
listOfThings = new List<string>();
if (listOfThings is null || listOfThings.Count == 0)
Console.WriteLine("Null or empty second check.");