Afzaal Ahmad Zeeshan wrote:
hiding NullReferenceException is (IMO) not a very great update
It's not hiding a NullReferenceException; it's checking each level of the expression for null. In other words, this:
DateTime? dateOfBirth = user?.Profile?.DateOfBirth;
is equivalent to this:
// Look, ma - no exceptions!
DateTime? dateOfBirth = user != null && user.Profile != null ? user.Profile.DateOfBirth : default(DateTime?);
not this:
// Seriously, don't do this!
DateTime? dateOfBirth;
try
{
dateOfBirth = user.Profile.DateOfBirth;
}
catch (NullReferenceException)
{
dateOfBirth = null;
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer