DEV Community

Discussion on: Are there functions similar to Ruby's `dig` in other languages?

Collapse
 
lazerfx profile image
Peter Street • Edited

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.";