Skip to content

Array of classes or structures?

james Last

Asked May 26, 2006, 2:29 AM EDT1 answer
Share
LinkedInX

Hi,

I have a number of queue structures. I want to have multiple instances of these,

i.e   Instance 1        Instance 2        Instance 3      ...
      ------------        ------------        ------------
      queueA             queueB               queueC

I was thinking of usind a structure or a class to store the queues and then having an array of theses structures or classes.

As I am only storing queues what is the best object to hold them, a class, a structue or another data structure?

Thanks
Macca

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    You can use an ArrayList() to store a dynamic collection of objects. Like:

    using System.Collections;

    private ArrayList myQueues = new ArrayList();

    myQueues.Add(queue);

    You can then just use it like an array, however since an ArrayList stores them as objects you must cast it back to the correct type before you can use it. Like:

    int index = 0;
    Queue currentQueue = (Queue)myQueues[index]; 

    you can also remove objects dynamically. Like:

    myQueues.RemoveAt(index);

    or

    myQueues.Remove(); // removes the first object

    I think that is what you meant,

    Darren

    0