Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15711

VS 2019 [RESOLVED] Arraylist vs List(of String)

$
0
0
Hi,
I am looking for some guidance to understand arraylists versus string lists. I had an old application where I had all my arrays as arraylists. I am working on another application and decided to use List(of string) instead.

I keep getting (System.NullReferenceException: 'Object reference not set to an instance of an object.') errors, when I try to add a value to my string array or clear it.

Code:

Public Class Main_Frm

    Public Imported_IDS, ProductNo As List(Of String)

Private Sub Start_Btn_Click(sender As Object, e As EventArgs) Handles Start_Btn.Click

 Imported_IDS.Clear()
 ProductNo.Clear()

Imported_IDS.Add(Trim(textbox1.text))
ProductNo.add(textbox2.text))

end sub
end sub

I read that I need to redefine it as a new list(of string) before using it to initiate it and prevent the null error. the issue is I don't want to lose the values on the array, as I use it in other forms. I don't get those errors with arraylist. Is there a way to disable this exception or what is the best way to use string list.

Viewing all articles
Browse latest Browse all 15711

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>