private T checkDbNull<T>(T objVal, T ifnull)
{
if (!object.ReferenceEquals(objVal, System.DBNull.Value)) {
return objVal;
}
else {
return ifnull;
}
}
string str = checkNull<string>("Hej", "0");
decimal dec = checkNull<decimal>(0.5855, 0);
Frågan#1
Tänker mig en funktion som denna:
private object checkNull(object objVal, System.Type _type)
{
if (!object.ReferenceEquals(objVal, System.DBNull.Value)) {
return (_type)objVal;
}
else {
return (_type)0;
}
}
string str = checkNull("Hej", string);
decimal dec = checkNull(0.5855, decimal);
Men jag kanske är fel ute, denna funkar ju inte i alla fall.
