I have read several articles and questions on Stack Overflow and still cannot see what I am doing wrong. Not using C#6 -- sorry for not posting that at first. VS 2013.
This code works:
if (row.Cells["CSR_Notes"].Value != null)
{
deliveryEvent.CSR_Notes = row.Cells["CSR_Notes"].Value.ToString();
}
and this code works:
deliveryEvent.CSR_Notes = row.Cells["CSR_Notes"].Value != null
? row.Cells["CSR_Notes"].Value.ToString() : "";
But this code throws a "Object reference not set..." error if the value is null.
deliveryEvent.CSR_Notes = row.Cells["CSR_Notes"].Value.ToString() ?? "";
What am I missing?
(row.cells[...].Value ?? "").ToString()