Why is this compiler error when mixing C # ValueTuple and dynamic

When using ValueTupleand dynamic object, I got this strange error CS8133. I pass the dynamic object as input and take ValueTuple as output. Why do they affect each other.

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
}

Edit: Error message: CS8133 Cannot deconstruct dynamic objects

+4
source share
1 answer

See function specification :

rhs.Deconstruct(out var x1, out var x2, ...); . . , rhs Deconstruct ....

var. Deconstruct. , var (.. ).

, out var ( var out out local?).

+5

Source: https://habr.com/ru/post/1682544/


All Articles