📜  c# 可为空的泛型 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:19.459000             🧑  作者: Mango

代码示例1
static void Main(string[] args)
{
    int? i = GetValueOrNull(null, string.Empty);
}


public static Nullable GetValueOrNull(DbDataRecord reader, string columnName) where T : struct
{
    object columnValue = reader[columnName];

    if (!(columnValue is DBNull))
        return (T)columnValue;

    return null;
}