MichaelS MichaelS - 5 months ago 22
Vb.net Question

Is there a way to give meaningful names for Tuple items?

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?

Code:

Looking for something like this:

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


Instead of:

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

Answer

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

  • 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