No. The Tuple
类仅用于方法内部使用;如果您打算公开数据,您应该定义一个class
or struct
以及每个值的属性。
但是,如果您想为值指定有意义的名称,则可以使用匿名类型。这些都是受约束的(不仅仅是有意的)仅在方法内部使用。
var a = new { Name = "ABC", Age = 33, NumberOfFingers = 10 };
int age = a.Age;
Edit:如果您确信要从方法返回一个元组,那么我的建议是在方法返回值的文档中解释其结构。
/// <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);
}
如果您希望它显示在 IntelliSense 中,请将您的解释放在<summary>
.