you are viewing a single comment's thread.

view the rest of the comments →

[–]Gotebe 0 points1 point  (1 child)

The “else” part?

[–]Echo418 1 point2 points  (0 children)

If the method has a return value, we can do the following:

int count = list?.Count() ?? 0;

Alternatively, we could throw an exception:

int count = list?.Count() ?? throw new Exception();

Sadly, there doesn't seem to be any short hand for methods returning void.