With that awful `if` statement, you're calling the functions multiple times. It's negligible with the simple getters Java users use everywhere, but if that `getAccount()` call involved, say, the database, now you're making multiple calls when you don't have to.
C# at least has null propagation and pattern matching that can make that line:
if (getAccount()?.getContact()?.getPhoneNumber() is string pn) {
// do something with `pn`
}
The "idiomatic" C# way would also include properties:
if (GetAccount()?.Contact?.PhoneNumber is string pn) {
// do something with `pn`
}
C# at least has null propagation and pattern matching that can make that line:
The "idiomatic" C# way would also include properties: