Q: How to test an object for null in an elegant way in C#? I want to test if the Output.ScriptPubKey.Addresses array is null or not and then assign it to a parameter list. If it's null then I want to set the parameter value to 0, else use the number of items in the array.
What I've written below feels clumsy and verbose, is there a more elegant way?
int addressCount;
if (Output.ScriptPubKey.Addresses == null) { addressCount = 0; } else {
    addressCount = Output.ScriptPubKey.Addresses.Length;
}
var op = new DynamicParameters();
op.Add("@AddressCount", addressCount);

The code used to be: 
op.Add("@AddressCount", Output.ScriptPubKey.Addresses.Length);

but sometimes the Addresses array is empty.

A: You want the null-coalescing operator combined with the null conditional operator:
int addressCount = Output.ScriptPubKey.Addresses?.Length ?? 0;

The left-hand-side of the ?? operator will be used unless the result is null, in which case it will use 0.  The ?. evaluates against null and if any part of (a potential chain) evaluates to null, all of it evalutes to null.  Thus it short-circuits and allows you to compose expressions such as this.
