C# DBNull and nullable Types - cleanest form of conversion
问题 I have a DataTable, which has a number of columns. Some of those columns are nullable. DataTable dt; // Value set. DataRow dr; // Value set. // dr["A"] is populated from T-SQL column defined as: int NULL What, then, is the cleanest form of converting from a value in a DataRow, to a nullable variable. Ideally, I would be able to do something like: int? a = dr["A"] as int?; Edit : Turns out you CAN do this, the side effect being that if your Schema types arn't ints, then this is ALWAYS going to