ASP.NET Tutorial/LINQ/Generics
Версия от 18:30, 26 мая 2010; (обсуждение)
Understanding Generics
<source lang="csharp">
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"};</source>