小编use*_*770的帖子

将int转换为nullable int?

我需要知道如何将int转换为可以为null的int.但是,我不断收到错误"没有为类型'System.Nullable`1 [System.Int32]'和'System.Int32'定义二进制运算符Equal." 任何解决方案 它需要是Microsoft SQL Server的可空int类型.

 somevalue = Expression.Constant(something.GetValue(some,null).To<Nullable<System.Int32>> ());

public static T To<T>(this object obj)
    {
        Type t = typeof(T);
        Type u = Nullable.GetUnderlyingType(t);

        if (u != null)
        {
            if (obj == null)
                return default(T);

            return (T)Convert.ChangeType(obj, u);
        }
        else
        {
            return (T)Convert.ChangeType(obj, t);
        }
    }'
Run Code Online (Sandbox Code Playgroud)

c# asp.net

20
推荐指数
3
解决办法
5万
查看次数

标签 统计

asp.net ×1

c# ×1