By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,671 Members | 1,387 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,671 IT Pros & Developers. It's quick & easy.

which collection to use

P: n/a
Hi!

I need an array-type of collection when the entries would look like:
object myObject, int myInt, string myString

Which collection should I use?
I know I could declare a multidimensional array of objects but adding and
deleting to that
array would require distribution of objects each time something was deleted
or added so
that doesn't feel like the correct approach.

Thanks,
saso
Nov 15 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Saso,

One suggestion would be to create a custom type,
(say something like the MyEntry class shown below)
that contains the fields (In your example -
object myObject, int myInt, string myString)
that comprise the entries to be added to the collection.

You can then add/remove instances of the MyEntry class
from a collection such as the ArrayList.

public class MyEntry
{
private object _myObject;
private int _myInt;
private string _myString;

// Expose a few public properties here to
// access/modify the private fields
// ...
}

ArrayList list = new ArrayList();
list.Add(new MyEntry(myObj, myInt, myString));

You could also create a strongly typed collection
class derived from CollectionBase that could allow you to
add and remove instances of MyEntry.

Regards,
Aravind C
"Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message
news:c0**********@planja.arnes.si...
Hi!

I need an array-type of collection when the entries would look like:
object myObject, int myInt, string myString

Which collection should I use?
I know I could declare a multidimensional array of objects but adding and
deleting to that
array would require distribution of objects each time something was deleted or added so
that doesn't feel like the correct approach.

Thanks,
saso

Nov 15 '05 #2

P: n/a
There are many types of collections. Even specialized ones. Could you
provide us with some more information like what is needed : fast adding,
fast removing, strict order, looking up if an item is in the collection
based on one of the fields you specified (which one), ...
Each collection type has it's own benefits.

Yves

"Saso Zagoranski" <sa*************@guest.arnes.si> schreef in bericht
news:c0**********@planja.arnes.si...
Hi!

I need an array-type of collection when the entries would look like:
object myObject, int myInt, string myString

Which collection should I use?
I know I could declare a multidimensional array of objects but adding and
deleting to that
array would require distribution of objects each time something was deleted or added so
that doesn't feel like the correct approach.

Thanks,
saso

Nov 15 '05 #3

P: n/a
I need adding, removing and searching. Nothing special really... No real
speed
requirements either.

Aravind's idea seem ok... what do you think?

"phoenix" <pa******@skynetWORK.be> wrote in message
news:eG**************@tk2msftngp13.phx.gbl...
There are many types of collections. Even specialized ones. Could you
provide us with some more information like what is needed : fast adding,
fast removing, strict order, looking up if an item is in the collection
based on one of the fields you specified (which one), ...
Each collection type has it's own benefits.

Yves

"Saso Zagoranski" <sa*************@guest.arnes.si> schreef in bericht
news:c0**********@planja.arnes.si...
Hi!

I need an array-type of collection when the entries would look like:
object myObject, int myInt, string myString

Which collection should I use?
I know I could declare a multidimensional array of objects but adding and deleting to that
array would require distribution of objects each time something was

deleted
or added so
that doesn't feel like the correct approach.

Thanks,
saso


Nov 15 '05 #4

P: n/a
I would create a class with the elements in it. If you would search on the
string you might want to check out the StringDictionary class. Otherwise
you're best of using an ArrayList.

Yves

"Saso Zagoranski" <sa*************@guest.arnes.si> schreef in bericht
news:c0*********@planja.arnes.si...
I need adding, removing and searching. Nothing special really... No real
speed
requirements either.

Aravind's idea seem ok... what do you think?

"phoenix" <pa******@skynetWORK.be> wrote in message
news:eG**************@tk2msftngp13.phx.gbl...
There are many types of collections. Even specialized ones. Could you
provide us with some more information like what is needed : fast adding,
fast removing, strict order, looking up if an item is in the collection
based on one of the fields you specified (which one), ...
Each collection type has it's own benefits.

Yves

"Saso Zagoranski" <sa*************@guest.arnes.si> schreef in bericht
news:c0**********@planja.arnes.si...
Hi!

I need an array-type of collection when the entries would look like:
object myObject, int myInt, string myString

Which collection should I use?
I know I could declare a multidimensional array of objects but adding and deleting to that
array would require distribution of objects each time something was

deleted
or added so
that doesn't feel like the correct approach.

Thanks,
saso



Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.