I just cannot figure out what is needed to resolve the warning about the possible null reference assignment in the following case:
item.UniqueId = Convert.IsDBNull(reader["UniqueID"]) ? string.Empty : reader["UniqueID"].ToString()
If the field value is NULL, it should set the property to an empty string, otherwise it should set it to the field value converted to a string. The field is defined as PK, varchar(11), not null.
if I define the UniqueID property as string? then the warning goes away, but it cannot be null so I don't want to do that.
I was under the impression that ToString() cannot return a null result.
Object.ToStringisString?.not null, then when would you ever get a DBNull object? Could you not just doreader["UniqueID"].ToString() ?? string.Empty?