2012-06-08 54 views
-1

我想在Sub過程之上聲明一個列表並且能夠添加/修改它。如何聲明一個全局列表對象

我想有這樣的事情:

Public lisst As List(Of Decimal) 
Private Sub angajati_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
     lisst.Add(1) 
     lisst.Add(2) 
End Sub 

當我運行上面的例子我得到這樣一個錯誤:

Object reference not set to an instance of an object. 

我怎麼能解決問題呢?

回答

2

您還沒有初始化列表(注意New):

Public lisst As New List(Of Decimal) 
Private Sub angajati_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
     lisst.Add(1) 
     lisst.Add(2) 
End Sub