Using the C# Safe Navigation Operator for writing cleaner code .?

The Elvis-operator .?(also called the Safe Navigation Operator) can be used to flatten down your syntax tree significantly.

The following code for example.

The example above is 5 levels of nestings deep, not counting the function.

Using the safe navigation operator, we could drill this down to only 1 level (the one that matters).

.?

Much better!

Like what you read? Give Maarten Merken a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.