问题
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
回答1:
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.)
来源:https://stackoverflow.com/questions/54942526/is-possible-to-create-a-generic-list-of-named-tuples-in-visual-basic