To use generics, you need to import the System.Collections.Generic namespace.
List<string> stuffToBuy = new List<string>();
stuffToBuy.Add("socks");
stuffToBuy.Add("beer");
stuffToBuy.Add("cigars");
Here's how you would declare the list of strings in VB.NET:
Dim stuffToBuy As New List(Of String)
stuffToBuy.Add("socks")
stuffToBuy.Add("beer")
stuffToBuy.Add("cigars")
By taking advantage of collection initializers,
declare a strongly typed list of strings in a single line like this (in C#):
List<string> stuffToBuy2 = new List<string> {"socks", "beer", "cigars"};
17.3.Generics |
| 17.3.1. | Understanding Generics |