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" ?
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;
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>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With