当前位置: 动力学知识库 > 问答 > 编程问答 >

vb.net - How to declare a global list object

问题描述:

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
分享给朋友:
您可能感兴趣的文章:
随机阅读: