Hi. I need some help with arraylists. i can do a basic arraylist which uses integers and strings and so on. but what i need is an arraylist composed of something else.

best would be an arraylist composed of arraylists. like a multi dimensional array. is it possible to create multi dimensional arrays and if it is then how does one use it? if you guys can just give me basic guide lines for creating, adding, reading and removing

otherwise can i use the array list with an array of strings. or with a set of class objects. if i use it with an array of strings then what do i use as in the cast operation? can i just use the string array int the form (string[])? and if i use class objects which i create then i suppose that i can use the class in the cast

hi! I think you need to use generic arraylist.
which helps you to add only string in arraylist or class in arraylist.
hope that it works for you.

regards,
purunep

ok, here is an example: data is stored in xml and represents the table, need array list of array lists of xml nodes to do some intelligent sorting

ArrayList _arrMaster = new ArrayList

foreach(XmlNode rNode in XmlTable)
{
    if(IsStartOfGroup(rNode)) //if we need to start up a group I need a new array list
    {
        ArrayList _arrSub = new ArrayList();
        _arrSub.Add(rNode);
         /*add few more xml nodes and then move to the next group */
        _arrMaster.Add(_arrSub);
    }
}

this is very simplified, but at the end you get:

ArrayList that holds multiple array lists that holds multiple xml nodes that should be grouped together for some reason.

to work this:

private void ReIndexMaster(ref ArrayList master)
        {
            int iRowCount = 1;
            int iCellCount = 1;
            foreach(ArrayList tmp in master)
            {
                foreach(XmlNode rNode in tmp)
                {
                    rNode.Attributes["index"].Value = iRowCount.ToString();
                    rNode.Attributes["o_index"].Value = iRowCount.ToString();
                    iRowCount += 1;
                    iCellCount = 1;

                    foreach(XmlNode cNode in rNode)
                    {
                        cNode.Attributes["index"].Value = iCellCount.ToString();
                        iCellCount += 1;
                    }
                }
            }
        }

So the answer - multi dimensional arrays are good for you and are possible. Remember ArrayList holds object and everything is an object (even collections like arraylsits)so there is no limit. I have simplified this example but using casting you can get to any element within a top or bottom level of your arraylist.

Paul

This article has been dead for over six months. Start a new discussion instead.