【问题标题】:vb.net: list of typed class, how to add items like C#?vb.net:类型化类的列表,如何添加 C# 之类的项目?
【发布时间】:2014-12-04 10:42:58
【问题描述】:

在 vb.net 我有这个类:

public Class Articulo
  Public Id As Integer
  Public Name As Integer
  Public Precio As Double
End Class

您知道,使用 C# 我们可以添加以下项目:

List<Articulo> list = new List<Articulo>();

list.add(new Articulo() {
  Id = 1,
  Name="xxx1"
});

list.add(new Articulo() {
  Id = 2,
  Name="xxx2"
});

在vb.net中可以做到吗?

【问题讨论】:

标签: .net vb.net declaration generic-list


【解决方案1】:

是的,可以使用 With 关键字:

Dim list As New List(Of Articulo)()

list.add(New Articulo() With {.Id = 1, .Name="xxx1"})

list.add(New Articulo() With {.Id = 2, .Name="xxx2"})

【讨论】:

  • 你也可以添加一个匿名类型:list.add(New With {.Id = 1, .Name="xxx1"})
猜你喜欢
  • 2018-05-27
  • 1970-01-01
  • 1970-01-01
  • 2023-04-03
  • 2016-01-20
  • 2017-02-13
  • 2011-09-24
  • 2017-05-11
  • 1970-01-01
相关资源
最近更新 更多