ArrayList Class

Overview

  • Resizeable, unordered, index-based collection.
  • Suffers from boxing/unboxing when working with value types.
  • Implements IEnumerator, allowing foreach operations.

Good practice

Examples

Adding and Removing Elements

ArrayList a = new ArrayList();
a.Add(16);
a.AddRange(new object[] { "Hello", "World" });
a.Insert(0, "Start");
a.InsertRange(2, new int[] { 32, 64 });
foreach (var o in a) { Console.WriteLine(o); }
 
a.Remove("Hello");
a.RemoveAt(1);
a.RemoveRange(1, 2);
foreach (var o in a) { Console.WriteLine(o); }

Checking Existence

ArrayList a = new ArrayList();
a.AddRange(new object[] { "Hello", "World" });
Console.WriteLine(a.Contains("World") ? "World Found" : "World Missing");
 
learning/exam70-536/arraylist.txt · Last modified: 2008/09/16 15:43 by david
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki