c# - null / DBNull conversion -
this question has answer here:
i have method
void addparam(string name, object value); and object
public class foo { public string whatever; } what best way perform (working) call match logic?
addparam("foo", foo.whatever == null ? dbnull.value : foo.whatever); i thinking such thing this:
object getparamvalue(object value) { if (value == null) return dbnull.value; return value; } addparam("foo", getparamvalue(valuefoo.whatever)); how can achieve behavior?
you can use null coalesce operation:
addparam("foo", foo.whatever ?? dbnull.value);
Comments
Post a Comment