C# equivalent of the IsNull() function in SQL Server

前端 未结 10 2078
太阳男子
太阳男子 2020-12-12 21:53

In SQL Server you can use the IsNull() function to check if a value is null, and if it is, return another value. Now I am wondering if there is anything similar

10条回答
  •  眼角桃花
    2020-12-12 21:56

    You Write Two Function

        //When Expression is Number
        public static double? isNull(double? Expression, double? Value)
        {
            if (Expression ==null)
            {
                return Value;
            }
            else
            {
                return Expression;
            }
        }
    
    
        //When Expression is string (Can not send Null value in string Expression
        public static string isEmpty(string Expression, string Value)
        {
            if (Expression == "")
            {
                return Value;
            }
            else
            {
                return Expression;
            }
        }
    

    They Work Very Well

提交回复
热议问题