In C# 7 is it possible to deconstruct tuples as method arguments

You can shorten it to:

void test( Action<ValueTuple<string, int>> fn)
{
    fn(("hello", 10));
}

test(((string s, int i) t) =>
{
    Console.WriteLine(t.s);
    Console.WriteLine(t.i);
});

Hopefully, one day we might be able to splat the parameters from a tuple to the method invocation:

void test(Action<ValueTuple<string, int>> fn)
{
    fn(@("hello", 10)); // <-- made up syntax
}

test((s, i) =>
{
    Console.WriteLine(s);
    Console.WriteLine(i);
});

But not at the moment.

Leave a Comment