Skip to content
Discussion options

You must be logged in to vote

It's just a compile-time annotation to help developers be wary of potential nulls. Under the hood string or string? is the same type. "!" is just a "a know better than you, compiler" indicator. There are no casts involved.

It's a different story with Nullable type - it's designed to enable "nullness" for ValueTypes. It's essentially a wrapper - a different type - which holds some value inside it and indicates whether that value was initialized properly or not (kinda "null"). It has a special runtime treatment in some cases like boxing.

So basically "referenceType? (e.g. string?)" is just an compile time annotation and "valueType? (e.g. int?)" is a container type wrapping original value.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@TahirAhmadov
Comment options

Answer selected by moneer-muntazah
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants