• KindaABigDyl@programming.dev
    link
    fedilink
    arrow-up
    14
    ·
    2 days ago

    As others said, it means nullable, but to put it in more intuitive, less-jargony way - it’s a question mark bc you don’t know if the value is actually there or not. It could be a Singleton, but it isn’t until you check if there is a value. Whereas if you have, idk, int a no question mark, then you’re saying you actually have data.

    Essentially with C# 8, they “removed” null and reused the idea of null references in creating what is essentially an Option like in other languages. You either have some data of some type, or none (a null reference, in this case). By default, everything has to be there. Then when you need null, e.g. you may not have something initialized or an operation could fail, you explicitly grab for it. Thus it reduces null pointer bugs. If you don’t need nullability, you can ensure that you don’t accidentally write in an issue. It safety checks statements and parameters.