Somehow we've gone full circle, and you're arguing my position back to me.
That code sample is exactly how I'd write it. My only problem is that DBNull ever existed in the first place.
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);