Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Description to each Tuple object?

Tags:

c#

.net

.net-4.0

I have a tuple of :

var a = new Tuple<int, int, int>(1,2,3);

My question :

is there any way (by /// remark or something else ), to add a short description to the object types ?

the first 3 int's can be confusing....

How can I know that item1 is refering to "age" and not to "Number of fingers" ?

enter image description here

like image 651
Royi Namir Avatar asked Dec 04 '22 18:12

Royi Namir


1 Answers

No. The Tuple class is only intended to be used internally within a method; if you intend to make the data available publicly, you should define a class or struct with properties for each of your values.

However, if you want to give meaningful names to your values, you could use anonymous types instead. These are constrained (not just intended) to only be used internally within a method.

var a = new { Name = "ABC", Age = 33, NumberOfFingers = 10 };
int age = a.Age;

Anonymous type

Edit: If you’re convinced you want to return a tuple from your method, then my suggestion would be to explain its structure within the documentation for the return value of your method.

/// <summary>
/// Retrieves personal information about the person.
/// </summary>
/// <returns>
/// A tuple containing the following information:
/// <list type="bullet">
/// <item><see cref="Tuple{T1,T2,T3}.Item1"/>: The name of the person.</item>
/// <item><see cref="Tuple{T1,T2,T3}.Item2"/>: The age of the person.</item>
/// <item><see cref="Tuple{T1,T2,T3}.Item3"/>: The number of fingers the person has.</item>
/// </list>
/// </returns>
public Tuple<string, int, int> GetPerson()
{
    return Tuple.Create("ABC", 33, 10);
}

If you want it to show up in IntelliSense, place your explanation in the <summary>.

like image 197
Douglas Avatar answered Dec 23 '22 06:12

Douglas