3 ms·
They are called Nullable types in C# and must be declared with `?` after the type. But, Nullable<T>.HasValue check is not forced and Nullable<T>.Value will thr
by iCarrot 7y ago
They are called Nullable types in C# and must be declared with `?` after the type.
But, Nullable<T>.HasValue check is not forced and Nullable<T>.Value will throw a different exception instead if it is null (InvalidOperationException).
- to11mtm 7y agoWell, Depends on which type you are referring to (Which is part of what pains me with nullable ref types, as nice as it is to have) If it's a value type (T), ? will make it Nullable<T> and provide the behavior described. Reference types however can always be null, and do not have a .HasValue as exampled above. However newer versions of C# let you declare nullable references on a compiler level, but rather than HasValue/Value you still have to do the null check and instead can bypass via the new deref operator (!)
- LorenPechtel 7y agoWhich is what I was talking about. I haven't had the opportunity to put it to use yet (converting an existing project is a big headache, it's something to do from the start) so I didn't remember the terms, only the ability.