BP Forums
Keeping Track of Multiple Things (Alternative to an Array) - Printable Version

+- BP Forums (https://bpforums.info)
+-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55)
+--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56)
+---- Forum: VB.NET (Visual Basic 2010/2008) (https://bpforums.info/forumdisplay.php?fid=8)
+----- Forum: Code Snippets (https://bpforums.info/forumdisplay.php?fid=18)
+----- Thread: Keeping Track of Multiple Things (Alternative to an Array) (/showthread.php?tid=431)



Keeping Track of Multiple Things (Alternative to an Array) - brandonio21 - 11-27-2011

I thought that some of you may find this useful, It is the List object in VB.NET, which allows you to hold several things in one object. For example, if you have several strings.

[code2=vbnet]Dim str1 As String = "Hello"
Dim str2 As String = "My"
Dim str3 As String = "Name"
Dim str4 As String = "Is"
Dim str5 As String = "Brandon"
Dim strList As List(Of String)
strList.Add(str1)
strList.Add(str2)
strList.Add(str3)
strList.Add(str4)
strList.Add(str5)

Dim total As String = ""
For Each item In strList
total = total + " " + item
Next
Msgbox(total)[/code2]
This code will print out a MessageBox with the text of "Hello My Name Is Brandon "

Obviously this is not the best use for Lists, but they may come in handy when doing something else, so be sure to play around with them!