Vaccano Vaccano - 1 year ago 88
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 Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download