Possible to initialize multiple variables from a tuple?

前端 未结 7 481
孤独总比滥情好
孤独总比滥情好 2021-01-17 10:17

In some languages (such as PHP, Haskell, or Scala), you can assign multiple variables from tuples in a way that resembles the following pseudocode:

list(stri         


        
7条回答
  •  攒了一身酷
    2021-01-17 10:47

    This is now available in C# 7:

    public (string first, string last) FullName()
    {
        return ("Rince", "Wind");
    }
    
    (var first, var last) = FullName();
    

    You can even use a single var declaration:

    var (first, last) = FullName();
    

    More on destructuring tuples in the official documentation.

提交回复
热议问题