8

In C# (7+) I can declare (Better naming in Tuple classes than "Item1", "Item2")

var myList = new List<(int first, int second)>();

and later on refer to items:

var a = myList[0].second;

Is there an equivalent syntax in VB.NET?

Edit From Andrew Morton's answer, the equivalent syntax is:

Dim myList = New List(Of (first As Integer, second As Integer))
Dim a = myList(0).second
Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
IvanH
  • 5,039
  • 14
  • 60
  • 81

1 Answers1

14

Yes, see Tuples (Visual Basic).

Dim q As New List(Of (EventDate As Date, Name As String, IsHoliday As Boolean))
q.Add((EventDate:=#2019-01-01#, Name:="New Year's Day", IsHoliday:=True))
q.Add((New DateTime(2019, 6, 21), "Summer solstice", False))

Console.WriteLine(q(0).Name) ''outputs "New Year's Day"
Console.WriteLine(q(1).IsHoliday) ''outputs False

(Visual Studio 2017 and later.)

Andrew Morton
  • 24,203
  • 9
  • 60
  • 84