What's the purpose of the Tuple(T1)/Singleton in .net?

后端 未结 4 1770
难免孤独
难免孤独 2020-12-03 13:06

One of the Tuple Types in .net 4 is a Single-Element Tuple. I just wonder what the purpose of this struct is?

The only use I saw is when using in the 8+ Tuple as it

4条回答
  •  忘掉有多难
    2020-12-03 14:08

    You'd have to ask the BCL designers to be certain, but I suspect that since there is a 1-tuples in the real world, the .NET framework authors wanted to provide equivalent symmetry in their implementation.

    Tuples are the .NET implementation of what you'd consider the mathematical concept of a tuple.

    Now since you're asking for programming uses for Tuple, I would also answer that there are .NET languages (like F#) that could use Tuple<> for representation of things like return values from functions. Since an F# function could certainly return a 1-tuple as a result - it adds symmetry and consistency to the behavior and feel of the language.

    Your example with 8+ tuples is also probably legitimate, in that the Rest property could be a 1-tuple to represent the "overflow".

提交回复
热议问题