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

前端 未结 10 2098
太阳男子
太阳男子 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 22:11

    public static T isNull(this T v1, T defaultValue)
    {
        return v1 == null ? defaultValue : v1;
    }
    
    myValue.isNull(new MyValue())
    

提交回复
热议问题