Reputation: 1528
On one hand, a tuple is versatile, but on the other, can be less clear.
As a best practice, should tuple not be used for the return type of a public method? Similarly, should it not be used for the type of any parameter of a public method?
In other words, should it only be used in declarations of protected, internal, and private methods?
Upvotes: 1
Views: 348
Reputation: 24167
I would tend to use the same guidance that I do for "raw" collection types like Dictionary<TKey, TValue>
-- use something a bit more strongly typed. Inside your own internal methods it's fine, but use a more domain-specific type as a public input or output value.
Upvotes: 1
Reputation: 118895
Ths issue is not public v private, the issue is simply 'what is good API design'. I think that you would rarely use Tuple in a C# API, and in the rare cases you do use it, most commonly it would be for a return type (when you want to return multiple things). But one should not be too prescriptive with overly general rules ("A foolish consistency..."); do the right thing for each individual situation. There may be cases for using it in parameters (especially e.g. in some interop with other languages).
Upvotes: 1