And even better, use generic lists whenever possible. Since they came out in 2.0, I don't think I've ever used a plain ArrayList.
List<string> myNames = new List<string>();
myNames.Add("kevin");
string[] myNamesTurnedToStringArray = nyMames.ToArray();
Taking things one step further, I find that nearly every time I need a collection, I need it for more then a few simple statements. If you find that you are hitting your list all over your codebase, you might consider subclassing the List
public class Widgets : List<Widgets> // Widgest class defined elsewhere
{
public Widgets() : base() {}
public Widgets(IEnumerable<Widgets> items) : base(items) {}
public Widget GetWidgetById(int id)
{
// assuming only one ID possible
return this.Where(w => w.id == id).Single();
}
public string[] GetAllNames()
{
return this.Select(w => w.Name).ToArray();
}
}
//... later in some other class ....
Widgets w = new Widgets(dataFromDatabase);
Widget customerWidget = w.GetWidgetById(customerWidgetId);
string[] allNames = w.GetAllNames();
This is a nice OOPy way of encapsulating your list functionality in one place & often is a great way to separate your concerns organically.