0
所以這裏是我的問題。我有一個產品類,我創建了該類的ArrayList。 我可以將很多新產品添加到該陣列,但問題是陣列將數組的所有值更改爲我添加的最後一個值。ArrayList更改值,當我添加一個新的VB.NET
產品類別:
Public Class Product
Dim cod_prod As String
Dim state As Boolean
Public Sub New(ByVal cod As String, ByVal est As Boolean)
cod_prod = cod
state = est
End Sub
Public Sub New()
cod_prod = ""
state = False
End Sub
Public Function get_cod_prod() As String
Return cod_prod
End Function
Public Function get_state() As Boolean
Return state
End Function
Public Sub set_cod_prod(ByVal cod As String)
cod_prod = cod
End Sub
Public Sub set_state(ByVal est As Boolean)
state = est
End Sub
End Class
而且這個類是被我添加一個新的產品到ArrayList。
Dim array_prod As New ArrayList
Dim nproducts As Integer = 0
Public Sub add_prod(ByVal prod As Producto)
array_prod.Add(prod)
nproducts += 1
End Sub
感謝您的幫助。
試試這個: 暗淡array_prod()作爲新的ArrayList – Ibra 2014-11-21 11:12:15
沒有,這使得編譯錯誤。 – Fernando 2014-11-21 11:14:35
我看不到變量'array_prod'是一個數組 – Ibra 2014-11-21 11:15:57