Vaccano Vaccano - 1 month ago 6
C# Question

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

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

In C# 7.0 (VS 2015 preview 4) there is a new construction to do that:

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