Is there any way to convert from DB.Null to decimal in C#?
Like
Object[] returnvalue = new Object[1];
returnvalue[0] = null;
returnvalue[0] = Convert.ToDecimal(returnvalue[returnvalue.Length - 1]);
Though CLR is saying that DBNull.Value cannot be type casted. Still I want to know is there
any work around?
Thanks in advance
How do you expect to cast
nullto anything? It’s null, nothing, nada…That said, your best bet would be to check for
DBNull(ornullin the above case) and use/return/whateverdefault(decimal)instead, thoughnullandDBNullboth have a significant semantic difference from just a default value; they are the absence of a value, so this is probably not what you want to do.