DBNull
is a singleton. There is only one instance of it. You access this instance with DBNull.Value
. The comparison checks if DBNull(.Value)
is returned and if it is not returned (!=
) then it knows it can safely cast it to a DateTime
.
From MSDN:
DBNull is a singleton class, which means only this instance of this class can exist.
Alternatively you could use the Convert.IsDBNull
method:
if (!Convert.IsDBNull(reader["Birthdate"]))
{
info.Birthdate = (DateTime)reader["Birthdate"];
}