I’ll spend some time in this article reviewing some of the more common ways of handling String collections in VB.NET. Arrays in VB.NET do behave somewhat uniquely in several key aspects and working with them does take some getting used to for developers coming from a C# or Java background.
As with most things, there are several different ways of working with collections of strings in VB.NET:
- As a standard String array:
Dim saTest As String(9)
- As a List collection:
Dim lstTest As New List(Of String)
- As a StringCollection:
Dim scTest As New StringCollection()
Further, VB.NET does need special consideration when working with MutiDimensional and jagged MultiDimensional arrays. Your MultiDimensional options are:
- Directly manipulating a MutiDimensional array:
Dim saTest(1,0) As String
- Working with jagged MultiDimensional arrays using embedded collections (i.e.: List embedded in List, or Dictionary embedded in List):
Dim lstTest As New List(Of Dictionary(Of String, String))
If you find this article to be useful, I have more VB.NET articles available on a range of topics that are worth a look.