我有一些非常古老的 VB.Net 代码是:
Private Function Min(ByVal A As Object, ByVal B As Object) As Object
If A Is DBNull.Value Or B Is DBNull.Value Then Return DBNull.Value
If A < B Then Return A Else Return B
End Function
不用担心。编译器吃掉它......并要求更多。但是当转换为 C# 时:
private object Min(object A, object B)
{
if (object.ReferenceEquals(A, DBNull.Value) | object.ReferenceEquals(B, DBNull.Value))
return DBNull.Value;
return A < B ? A : B;
}
编译器阻塞它并显示错误消息:
Cannot apply operator '<' with operands of object and object
那么,到底是什么东西哟?