我有一个名为' account'的班级。这是代码:
Public Class Account
Private accounttype As String
Private accountnumber As Integer
Private branchcode As String
Private currency As String
Private balance As Integer
Public Sub New()
accounttype = " "
accountnumber = 0
branchcode = " "
currency = " "
balance = 0
End Sub
Public Sub New(ByVal cu As String, ByVal na As Integer, ByVal su As String, ByVal a1 As String, ByVal a2 As Integer)
accounttype = cu
accountnumber = na
branchcode = su
currency = a1
balance = a2
End Sub
Public ReadOnly Property Getaccountnumber() As String
Get
Return accountnumber
End Get
End Property
Public ReadOnly Property Getbalance() As Integer
Get
Return balance
End Get
End Property
Public Overrides Function ToString() As String
Return "Account Type: " & accounttype & vbCrLf & "Account Number: " & accountnumber.ToString & vbCrLf & "Branch Code: " & branchcode & vbCrLf & "Currency: " & currency & vbCrLf & "Balance: " & balance.ToString
End Function
End Class
然后我对这样的几个帐户进行了硬编码。
Dim account1 As New Account("Savings", "1", "S1", "Khajalee", 1000)
accodetails.Add(account1)
我想知道如何实现平衡'数组中的帐户值。任何帮助都会很精彩!!正如你所看到的那样,我尝试用几个不同的代码来获得平衡,但没有运气。
谢谢
答案 0 :(得分:0)
由数组"提供,你的意思是accodetails
,然后你可以通过索引访问数组中的任何项目,如下所示:
Dim myAccount As Account = accodetails(0)
然后,您可以通过该变量访问Account
对象中的任何属性,如下所示:
Dim myBalance As Integer = myAccount.GetBalance
或者,更简单地说,您可以直接从列表中的项目访问该属性,而无需将其分配给变量,如下所示:
Dim myBalance As Integer = accodetails(0).GetBalance