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

前端 未结 7 877

For example I have

private void test(Action> fn)
{
    fn((\"hello\", 10));
}

test(t => 
 {
    var (s, i) = t;
    C         


        
7条回答
  •  心在旅途
    2020-12-09 15:20

    One option is to use TupleSplatter (https://github.com/chartjunk/TupleSplatter):

    using TupleSplatter;
    
    void test(Action fn)
    {
        fn.SplatInvoke(("hello", 10));
        // or
        ("hello", 10).Splat(fn);
    }
    
    test((s,i) => {
        Console.WriteLine(s);
        Console.WriteLine(i);
    });
    

提交回复
热议问题