appropriate collection class

  • Thread starter Thread starter Kiran A K
  • Start date Start date
K

Kiran A K

hi,
suppose in my application i need to perform a lot of
insertions and deletions on my data structure.
the ideal data structure in this scenario would be a linked list.
unlike java, c# does not have a built-in "LinkedList" class.
so which collection class should i use in C#?

regards,
kiran
 
It depends on what type of information you wish to hold in your
collection.

If you have a collection of objects or structs, I would suggest an
ArrayList (System.Collections.ArrayList) since you can store objects
within an array list. If you are using .NET Framework 2.0, then use
generics with an ArrayList so you dont have to box/unbox your objects.

If it isnt a collection of objects you could use a HashTable if you
need to store a specific key value (like a Primary Key value for
instance)

Then even further down than that, if you just want to store string
values, you could use a string array.

There is multiple options here, it all depends on how you will be
representing the data in your business logic. I personally try to use
structs/classes as much as possible, because this allows me to not only
store the data, but also additional business rules within the classes
that may pertain to my business logic. It just makes it easier and more
modularized.

For more info look into the System.Collections namespace, as there is
alot more options than what I have mentioned here.
 
Kiran A K said:
hi,
suppose in my application i need to perform a lot of
insertions and deletions on my data structure.
the ideal data structure in this scenario would be a linked list.
unlike java, c# does not have a built-in "LinkedList" class.
so which collection class should i use in C#?

Without knowing precisely what you are doing and if it is a performance
problem or just a nagging issue, I can't say for sure. Like DKode said
ArrayList or a Hashtable is fine, if you aren't in need of top line
performance. If performance is going to be an issue, LinkedLists are pretty
easy to write, just write one.
 
Back
Top