What is changed by applying nullable Operator on value type datatype that now it can store null.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As others have said, “?” is just shorthand for changing it to
Nullable<T>. This is just another value type with a Boolean flag to say whether or not there’s really a useful value, or whether it’s the null value for the type. In other words,Nullable<T>looks a bit like this:Obviously in the real code there are more methods (like
GetValueOrDefault()) and conversion operators etc. The C# compiler adds lifted operators which effectively proxy to the original operators forT.At the risk of sounding like a broken record, this is still a value type. It doesn’t involve boxing… and when you write:
that’s not a null reference – it’s the null value of
Nullable<int>, i.e. the one wherehasValueisfalse.When a nullable type is boxed, the CLR has a feature whereby the value either gets boxed to a null reference, or a plain boxed T. So if you have code like this:
The boxed values referred to by
o1ando2are indistinguishable. You can’t tell that one is the result of boxing a nullable type.