"Robert W." <Ro*****@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.com...
I have a situation where I have pairs of strings that I want to put into an
ArrayList and then later pull out of it.
To keep things simple I tried this to put them in:
arrayList.Add(new object[] {stringA, stringB});
That works fine. But I can't figure out how to unbox them into their
constituent components. Might anyone know a way? Or am I forced to create
simple class to define the object that the strings will initially be placed
into?
Hi,
You don't need to use an Array of object. You can use a string array instead.
Anyway... here is a sample program
using System;
using System.Collections;
class Test
{
public static void Main()
{
string[] pair1 = {"happy","Birthday"};
string[] pair2 = {"Peanut butter","Jelly"};
string[] pair3 = {"Good","Evil"};
// Fill ArrayList
ArrayList list = new ArrayList();
list.Add(pair1);
list.Add(pair2);
list.Add(pair3);
foreach(string[] pair in list)
{
Console.WriteLine("{0} AND {1}",pair[0], pair[1]);
}
}
}
OUTPUT
---------------------
happy AND Birthday
Peanut butter AND Jelly
Good AND Evil
Hope this helps
Bill