向每个元组对象添加描述? [英] Adding Description to each Tuple object?

查看:83
本文介绍了向每个元组对象添加描述?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个元组:

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

我的问题:

有没有(通过 ///备注或其他方式)的方式,向对象类型添加简短描述?

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

前3个 int的可能令人困惑...。

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

我怎么知道item1指的是年龄而不是数字的手指?

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

推荐答案

否。 Tuple 类只能在方法内部使用;如果您打算公开提供数据,则应定义一个 class struct ,并为每个值设置属性

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.

但是,如果您想给值赋予有意义的名称,则可以改用匿名类型。这些是 constrained (不是唯一的),只能在方法内部使用。

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);
}

如果您希望它显示在IntelliSense中,请在< summary>

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

这篇关于向每个元组对象添加描述?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆