ASP.NET Tutorial/LINQ/Generics — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
| |
Текущая версия на 11:58, 26 мая 2010
Understanding Generics
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"};