【发布时间】:2018-01-05 04:12:42
【问题描述】:
当使用ValueTuple 和动态对象时,我收到了这个奇怪的CS8133 错误。我将动态对象作为输入传递,并将 ValueTuple 作为输出。为什么会互相影响。
public static (string, string) foo(dynamic input)
{
return ("", "");
}
public void foo_test()
{
dynamic input = new { a = "", b = "" };
(string v1, string v2) = foo(new { a = "", b = "" }); //compiles fine
(string v3, string v4) = foo(input); //CS8133 Cannot deconstruct dynamic objects
var result = foo(input); //compiles fine
}
编辑:
错误信息是:CS8133 Cannot deconstruct dynamic objects
【问题讨论】:
-
错误信息是什么?
-
foo(input)->foo((object)input) -
@PetSerAl 但为什么。为什么编译器只在第二次调用时报错
-
@XiaoguoGe 调用
foo有dynamic参数(input),因此它是通过动态绑定完成的,有dynamic返回类型,但没有(string, string)。