我正在尝试声明类型Product并输入Productlist 谁能告诉我这是否是正确的方法呢?
Public Class Product
Public Property name As String
Public Property price As Double
End Class
Public Class ProductsList
Public Property items() As New List(Of Product)
End Class
我的意思是我可以写
Public Class Product
Public Property name As String
Public Property price As Double
End Class
Public property ProductsList as new List(Of Product)
相反?
答案 0 :(得分:1)
第一种方法似乎是更好的做法。您可以像这样编码:
Dim p as new Product()
p.name = "Apple"
p.price = 1
Dim pList as new ProductList()
pList.Items.Add(p)
第二种方法的问题是你会有一个包装类,例如DemoWrapper:
Public Class DemoWrapper
Public Class Product
Public Property name As String
Public Property price As Double
End Class
Public ProductsList as new List(Of Product)
End Class
您的代码最终会像这样:
Dim p as new DemoWrapper.Product()