One thing I've been doing a lot lately is using null coalescing for backups to as
. For example:
object boxed = 4;
int i = (boxed as int?) ?? 99;
Console.WriteLine(i); // Prints 4
It's also useful for backing up long chains of ?.
that could each fail
int result = MyObj?.Prop?.Foo?.Val ?? 4;
string other = (MyObj?.Prop?.Foo?.Name as string)?.ToLower() ?? "not there";