问题描述:

I would like to declare a list above Sub procedure and to be able to add/modify it .

I would like to have something like this:

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

When i run the above example i get an error like:

 Object reference not set to an instance of an object.

How could i solve the problem ?

网友答案:

You have not initialized the list (notice the 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
相关阅读:
Top