Csharp/CSharp Tutorial/Data Structure/IList — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 15:15, 26 мая 2010
IList<T>: add, insert, and remove some items
<source lang="csharp">using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Text; public class MainClass {
public static void Main() { IList<double> myList = new List<double>(); myList.Add(1.54); myList.Add(29.2234); myList.Insert(1, 39.99); myList.Add(48.2); myList.Remove(10.4); }
}</source>
IList<T>: enumerate the list using Count and IList<T>"s indexer
<source lang="csharp">using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Text; public class MainClass {
public static void Main() { IList<double> myList = new List<double>(); myList.Add(10.5); myList.Add(209.224); myList.Insert(1, 3.999); myList.Add(48.2); myList.Remove(10.4); for (int i = 0; i < myList.Count; i++) Console.WriteLine(myList[i]); }
}</source>
10.5 3.999 209.224 48.2
IList<T>: print some specific element indexes
<source lang="csharp">using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Text; public class MainClass {
public static void Main() { IList<double> myList = new List<double>(); myList.Add(10.5); myList.Add(209.224); myList.Insert(1, 3.999); myList.Add(48.2); myList.Remove(10.4); Console.WriteLine("IndexOf {0} = {1}", 209.2234, myList.IndexOf(209.2234)); Console.WriteLine("IndexOf {0} = {1}", 10.54, myList.IndexOf(10.54)); }
}</source>
IndexOf 209.2234 = -1 IndexOf 10.54 = -1