【问题标题】:Is possible to create a generic list of named tuples in Visual Basic?是否可以在 Visual Basic 中创建命名元组的通用列表?
【发布时间】:2019-07-23 08:41:30
【问题描述】:

在 C# (7+) 中我可以声明 (Better naming in Tuple classes than "Item1", "Item2")

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

以后参考项目:

var a = myList[0].second;

VB.NET 中是否有等价的语法?

编辑 从 Andrew Morton 的回答来看,等效的语法是:

Dim myList = New List(Of (first As Integer, second As Integer))
Dim a = myList(0).second

【问题讨论】:

    标签: vb.net


    【解决方案1】:

    是的,请参阅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 及更高版本。)

    【讨论】:

      猜你喜欢
      • 2020-07-02
      • 1970-01-01
      • 2010-10-06
      • 2011-03-04
      • 1970-01-01
      • 2021-10-01
      • 2014-05-13
      • 2020-05-15
      • 2015-10-31
      相关资源
      最近更新 更多