我有以下的C#code:
I have the following C# code:
sqlCommand.Parameters.AddWithValue("@Parameter", table.Value ?? DBNull.Value);
但它引发以下编译错误:
But it throws the following compilation error:
操作 ??
不能应用于类型的操作数字符串
和 System.DBNull
Operator ??
cannot be applied to operands of type string
and System.DBNull
为什么没有编译器允许这种语法?
Why doesn't the compiler allow this syntax?
两个操作数需对象。使用显式类型转换:
Both operands need to be object. Use explicit cast:
(object)table.Value ?? DBNull.Value;