using System.Collections.Generic;
public static void Main()
Console.Write("Variable x is -> ");
Console.WriteLine(x == null ? "NULL" : x.ToString());
Console.Write("The collection inside of x is -> ");
Console.WriteLine(x.ThingsThatCanBeNull == null ? "NULL" : x.ThingsThatCanBeNull.ToString());
Console.Write("Trying to access null properties -> ");
Console.WriteLine((object)x.ThingsThatCanBeNull ?? (object)"NULL");
var y = x.ThingsThatCanBeNull?.Select(thing => thing.NumberOfFcksGiven).ToList();
var z = x?.ThingsThatCanBeNull?.Select(thing => thing.NumberOfFcksGiven).ToList();
Console.WriteLine("Null coalescing method calls prevents obj ref errors. ->\t" + $"{y == null && z == null}");
public IEnumerable<TestStuff> ThingsThatCanBeNull {get;set; }
public string IrrelevantProperty { get;set; }
public int NumberOfFcksGiven { get;set;}