What is the correct way to use values that may or may not have the value of null?
I have this piece of code that sends an email to a manager if the employee who is taking a holiday request has a manager.
if(holidayRequestForm.Employee.Site.SiteManagerEmail != null)
{
SendMailToManager();
}
However this is causing a NullReferenceException.
What would be the correct way to implement calling the SendMailToManager()
if that Employee has one without causing a NullReferenceException
.
Is it bad practise to use possible null values this way?