所以我有2个表单和一个类,在我的第一个表单上,它将项添加到字典中,在我的第二个表单上,它检查应该添加到字典上的项是否成功。但奇怪的是,在表单1中,它显示该项目已添加到字典中,但在我的第二种形式中,当我得到字典计数时,它产生0,这意味着那里没有任何内容。希望你能帮助我。
表格1
Public Class register
Dim acc_num As New System.Text.StringBuilder()
Dim account_info As New ArrayList()
Dim access_acc As New Accounts
Private Sub btn_save_Click(sender As Object, e As EventArgs) Handles btn_save.Click
Try
account_info.Add(fname_txt.Text & " " & lname_txt.Text)
account_info.Add("0.00")
access_acc.addAcc(account_number_lbl.Text, account_info)
MsgBox("Your account has been registered! Thank you for banking with us, your money is in good hands")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
表格2
Dim access_acc As New Accounts
Private Sub btn_process_Click(sender As Object, e As EventArgs) Handles btn_process.Click
MsgBox(access_acc.getCount().ToString)
End Sub
我的班级
Public Class Accounts
Private account As New Dictionary(Of String, ArrayList)
Public Sub addAcc(ByVal account_number As String, account_info As ArrayList)
account.Add(account_number, account_info)
MsgBox(account.Count)
End Sub
Public Function getCount() As Integer
Return account.Count
End Function
End Class