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
public static T IsNull(this T DefaultValue, T InsteadValue)
{
object obj="kk";
if((object) DefaultValue == DBNull.Value)
{
obj = null;
}
if (obj==null || DefaultValue==null || DefaultValue.ToString()=="")
{
return InsteadValue;
}
else
{
return DefaultValue;
}
}
//This method can work with DBNull and null value. This method is question's answer