我正在为一门课程编写 POS 应用程序。我在访问不同类中的 ArrayList 类型的 itemList 时遇到问题。下面是我的两个类的代码。是否可以访问另一个类(即 inside Transaction
)中的 arrayList ?
Public Class Item
'Declares item variables
Public itemName As String
Public itemPrice As Decimal
Public itemQty As Integer
Public itemSku As Long
Public itemList As New ArrayList
Public newItem As Item
'Method passes details of item
Public Sub AddItem(itemSku, itemName, itemPrice, itemQty)
itemSku = newItem.itemSku
itemName = newItem.itemName
itemPrice = newItem.itemPrice
itemQty = newItem.itemQty
itemList.Add(newItem) 'adds newItem to arrayList of items itemList
End Sub
End Class
Public Class Transaction
Dim subtotal As Decimal
Dim tax As Decimal
Dim total As Decimal
Dim paymentType As String
Public Function calculateBalance()
For count As Integer = 0 To itemList.Count 'TRYING TO ACCESS ARRAYLIST HERE
Next
End Function
End Class