#Nullable type semantics

1 messages · Page 1 of 1 (latest)

waxen musk
#

is

value.HasValue

always the same as

value != null

or

value is not null

Context: using System.Nullable<T>

#

Nullable type semantics

spice patio
#

Look at the compiled C#, all of them are the same.

rancid cliff
#

wouldn't they be different (specifically !=) for UnityEngine.Object

cinder hollow
rancid cliff
#

🤔 is Nullable<T> the same as T??

spice patio
#

Confusingly, no.

#

TStruct? is a syntax sugar for Nullable<TStruct>, which is a wrapper type that actually exists at runtime.
TClass? is just TClass but with NRT, which is just a compile time feature that doesn't exist at runtime.

#

This nullable divide brings not only confusion but also extra baggage when dealing with generics, think T? Get<T>().

ruby shadow
#

Yeah, I don't see a point in using nullables for reference types. It can be useful for structs, but too confusing otherwise.