C# 6.0 and onwards gives you the Null Propagating Operator MSDN Guide — like many of the other languages here, you would use it something like:
var customerName = orders[0]?.customer?.name;
This can be combined with the null coalescing operator, to give a default value:
var customerName = orders[0]?.customer?.name ?? "No value found.";
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
C# 6.0 and onwards gives you the Null Propagating Operator MSDN Guide — like many of the other languages here, you would use it something like:
This can be combined with the null coalescing operator, to give a default value: