我有一个方法
void addParam(string name, object value);和一个对象
public class Foo
{
public string Whatever;
}执行符合此逻辑的(工作)调用的最佳方式是什么?
addParam("foo", Foo.Whatever == null ? DBNull.Value : Foo.Whatever);我在想这样的事情:
object getParamValue(object value)
{
if (value == null) return DBNull.Value;
return value;
}
addParam("foo", getParamValue(ValueFoo.Whatever));如何实现此行为?
发布于 2013-05-15 02:18:40
您可以使用空合并操作:
addParam("foo", Foo.Whatever ?? DBNull.Value);https://stackoverflow.com/questions/16549925
复制相似问题