Re:.NET Framework 4.6.2
by gregmac on Wednesday August 03, 2016 @12:35PM
(#12219255)
Generally agreed, and out of curiosity I just looked through some fairly new code I have that's pretty heavy on C# 6, and only found a single instance of two null conditionals being used:
Next closest thing that shows up a few times is coalescing to a default value:
config?.OutputName ?? DefaultConfig.OutputName
Some other examples that show up a lot:
Invoke Action<> or Func<> that may be null or unassigned (this works for Events as well):
actionHandler?.Invoke(value);
Extracting a value from a LINQ expression on a list of container objects (this one is actually from a unit test where it's explicitly only expecting one item):
items.First()?.Data
Easy way to do a Coalesce on a specific property value in a collection:
Invoke Action<> or Func<> that may be null or unassigned (this works for Events as well):
Extracting a value from a LINQ expression on a list of container objects (this one is actually from a unit test where it's explicitly only expecting one item): Easy way to do a Coalesce on a specific property value in a collection: