Is there any penalty, such that you should only set them as nullable when you really need it?
Thanks
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.
Various reasons:
Nullable<T>didn’t exist until .NET 2.0, and it can’t break existing code – especially with the different boxing rules forNullable<T>int, I might not want it to be nullable… I want it to be anint, and I don’t want to have to check-for/handle nullsbyte[], and now consider ifbytewas nullable – lots of extra overhead; *plus it would stop you doing blits etc*Performance:
Nullable<T>adds lots of extra penalties; in particular lots of hidden calls to.HasValueand.Value/.GetValueOrDefault(); this is shown in particular in the “lifted operators” – i.e.x + ybecomes something like below, which adds up for tight loops etc:(x.HasValue && y.HasValue) ? (x.GetValueOrDefault() + y.GetValueOrDefault()) : nullLikewise,
x == yhas to check:==onGetValueOrDefault()of eachlots of overhead….