List(Of T) in Visual Basic
The growable collection: add, insert, remove, sort.
Dim guests As New List(Of String) From {"ada", "grace"}
guests.Add("alan")
guests.Insert(1, "edsger")
guests.Remove("grace")
Console.WriteLine(guests.Count)
Console.WriteLine(guests.Contains("ada"))
guests.Sort()
For Each name In guests
Console.WriteLine(name)
Next
Console.WriteLine(String.Join(", ", guests))
How it works
New List(Of String) From {...}seeds the list at construction.Insertplaces by position;Removedeletes by value.Sortorders in place;String.Joinprints it in one line.
Keywords and builtins used here
DimEachForNewNextOfString
The run, in numbers
- Lines
- 14
- Characters to type
- 313
- Tokens
- 98
- Three-star pace
- 90 tpm
At the three-star pace of 90 tokens a minute, this run takes about 65 seconds.
Step 2 of 3 in Collections, step 5 of 29 in Language basics.