If you're talking about value types then nullable value types exist, which are still structs:
https://docs.microsoft.com/en-us/dotnet/csharp/language-refe...
https://docs.microsoft.com/en-us/dotnet/csharp/language-refe...
I seem to be having some trouble explaining my point. Maybe this will illustrate better. What should be the declared return type of this method?
??? GetValue() {
if (condition) {
return 7;
}
else {
return DBNull.Value;
}
}int? someNumber = resultset.Records[0]["some_column"] as int?;
That code sample is exactly how I'd write it. My only problem is that DBNull ever existed in the first place.
I get that it was annoying, but most of .NET before 3.5 was anyway. It's just nobody bothered to make the right syntactic sugar.
Yes, I have a point of view.
There's really no reason why you have to touch DBNull at all.
var dt = new DataTable();
dt.Columns.Add("name", typeof(string));
//dt.Columns.Add("count", typeof(int?)); // NotSupportedException: DataSet does not support System.Nullable<>.
dt.Columns.Add("count", typeof(int));
var row=dt.NewRow();
row["name"] = null;
//row["count"] = null; // ArgumentException: Cannot set Column 'count' to be null. Please use DBNull instead.
row["count"] = DBNull.Value;
dt.Rows.Add(row);