Better naming in Tuple classes than "Item1", "Item2"

Vaccano picture Vaccano · Oct 12, 2011 · Viewed 129.7k times · Source

Is there a way to use a Tuple class, but supply the names of the items in it?

For example:

public Tuple<int, int, int int> GetOrderRelatedIds()

That returns the ids for OrderGroupId, OrderTypeId, OrderSubTypeId and OrderRequirementId.

It would be nice to let the users of my method know which is which. (When you call the method, the results are result.Item1, result.Item2, result.Item3, result.Item4. It is not clear which one is which.)

(I know I could just create a class to hold all these Ids, but it these Ids already have their own classes they live in and making a class for this one method's return value seems silly.)

Answer

MichaelMocko picture MichaelMocko · Oct 13, 2016

In C# 7.0 (Visual Studio 2017) there is a new construction to do that:

(string first, string middle, string last) LookupName(long id)