要将元素插入到指定索引处的ArrayList中,代码如下-
输出结果
这将产生以下输出-
ArrayList elements... One Two Three Four Five Six Seven Eight ArrayList is read-only? = False Does the element Six in the ArrayList? = True ArrayList elements...UPDATED One Two Three Four Twelve Five Six Seven Eight让我们看另一个例子-
using System; using System.Collections; public class Demo { public static void Main() { ArrayList arrList = new ArrayList(); arrList.Add(100); arrList.Add(200); arrList.Add(300); arrList.Add(400); arrList.Add(500); Console.WriteLine("Display elements..."); IEnumerator demoEnum = arrList.GetEnumerator(); while (demoEnum.MoveNext()) { Object ob = demoEnum.Current; Console.WriteLine(ob); } arrList.Insert(4, 1000); Console.WriteLine("Display elements...UPDATED"); demoEnum = arrList.GetEnumerator(); while (demoEnum.MoveNext()) { Object ob = demoEnum.Current; Console.WriteLine(ob); } } }输出结果
这将产生以下输出-
Display elements... 100 200 300 400 500 Display elements...UPDATED 100 200 300 400 1000 500