Is possible to create a generic list of named tuples in Visual Basic?

北城余情 提交于 2021-02-07 13:23:37

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!