Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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`
    }


Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: