Possible to initialize multiple variables from a tuple?

前端 未结 7 646
孤独总比滥情好
孤独总比滥情好 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:45

    Valid up to C# 6:

    No, this is not possible. There's no such language feature in C#.

    If you think the following code:

    string firstValue = tupleWithTwoValues.Item1;
    string secondValue = tupleWithTwoValues.Item2;
    

    is ugly, then you should reconsider using tuples at the first place.


    UPDATE: As of C# 7, tuple deconstruction is now possible. See the documentation for more information.

    See Jared's answer as well.

提交回复
热议问题