问题
I don't see the use of 1-tuples in C#. Why do programmers use them?
Tuple Class
I have seen a declaration like the following:
Tuple<string> state;
But I wonder if there are further uses.
回答1:
The Tuple classes only go up to 7. When you need an 8-tuple, you have to use
Tuple<T1, T2, T3, T4, T5, T6, T7, Tuple<T8>>
But if you need 8 items, you probably want to redesign your application.
You can go as far as you want, as long as you chain tuples together. 15 items:
Tuple<T1, T2, T3, T4, T5, T6, T7,
Tuple<T8, T9, T10, T11, T12, T13, T14, Tuple<T15>>>
Note that C# will throw a runtime exception if the last item (TRest) is not a tuple (since it cannot be enforced at compile-time because the ITuple interface is internal
)
来源:https://stackoverflow.com/questions/31134139/why-use-a-1-tuple-tuplet1-in-c