有没有办法为元组项目赋予有意义的名称? [英] Is there a way to give meaningful names for Tuple items?

查看:28
本文介绍了有没有办法为元组项目赋予有意义的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Tuple 检索项目是通过访问 ItemX 属性来完成的.有没有一种方法可以命名每个项目,以便使用元组更具可读性?

Retrieving items from a Tuple is done by accessing the ItemX property. Is there a way of naming each item so that using the Tuple will be more readable?

代码:

正在寻找这样的东西:

Dim l As New Tuple(Of String, Integer)
l.Name
l.ID

代替:

Dim l As New Tuple(Of String, Integer)
l.Item1
l.Item2

推荐答案

不,元组类型中没有任何内容可以帮助您解决这个问题.选项:

No, there's nothing in the tuple type that helps you out here. Options:

  • 如果您需要在多个方法中传递值,请使用适当的属性创建您自己的类型.(如果你真的想要,你可以Tuple 派生,并且只提供委托给 Item1Item2 的属性,但我不确定我会)
  • 如果您只需要一种方法中的值,请使用匿名类型
  • If you need to pass the values in multiple methods, create your own type with appropriate properties. (You could derive from Tuple here if you really want, and just provide properties which delegate to Item1 and Item2, but I'm not sure I would)
  • If you only need the values within one method, use an anonymous type

这篇关于有没有办法为元组项目赋予有意义的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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