[英]Why does the C# compiler think I'm trying to use the sbyte overload when using nullable longs?
The following code 以下代码
long? long1 = 1;
long? long2 = 2;
Math.Min(long1.Value, long2);
will result in the following error message on both arguments: 将在两个参数上导致以下错误消息:
I understand why this is an error, I know how to resolve the error. 我理解为什么这是一个错误,我知道如何解决错误。
My question is why is the compiler trying to choose the Math.Min(sbyte, sbyte)
overload in this case (even when the first argument is not a nullable)? 我的问题是为什么编译器在这种情况下尝试选择
Math.Min(sbyte, sbyte)
重载(即使第一个参数不可为空)?
它无法找到正确的重载,因此它默认为Math.cs中的第一个,恰好是public static sbyte Min(sbyte val1, sbyte val2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.