First, I wouldn't suggest using an ArrayList, unless you are stuck on .NET Framework 1.1.
System.Collections.Generic.List<T> is a much better, much more convenient construct to work with.
Now, it's actually pretty simple to just get a List of the items. If we're going to use a List, you have to be sure to cast properly. I'm assuming you're using Strings, but you could be using any object, so make sure to cast it to the proper type where I cast to string here:
- List<string> list = new List<string>();
-
foreach(object item in listBox.Items)
-
list.Add(item as string);
Just replace string with the type of object you added originally to the ListBox.
Alternatively, you can use LINQ:
- List<string> list = listBox.Items.Select(item => item as string).ToList();