What's the best collection
-
Hi all, I want to do something like this. A collection, which is not sorted in insertion(added in the next index) and avoid duplicate. Which can I use? Thanks. :)
I appreciate your help all the time... CodingLover :)
-
Hi all, I want to do something like this. A collection, which is not sorted in insertion(added in the next index) and avoid duplicate. Which can I use? Thanks. :)
I appreciate your help all the time... CodingLover :)
There is no set class in .NET. You'd have to add set behaviour to a list, by searching for items and not inserting them if they exist.
Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
-
Hi all, I want to do something like this. A collection, which is not sorted in insertion(added in the next index) and avoid duplicate. Which can I use? Thanks. :)
I appreciate your help all the time... CodingLover :)
AFAIK there isn't one. You can always create your own and use new a new Add method - something like
public class MyList<T> : List<T>
{
public new void Add(T item)
{
if (!Contains(item))
base.Add(item);
}
}You'll need to do something similar for AddRange, and keep track of any changing items to make sure they don't create duplicates.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
Hi all, I want to do something like this. A collection, which is not sorted in insertion(added in the next index) and avoid duplicate. Which can I use? Thanks. :)
I appreciate your help all the time... CodingLover :)
There is library available from Wintellect that has unordered set, the one you are looking for. You might try it if you wish.
http://vivekragunathan.spaces.live.com
Programming is an art. Code is a poem
-
Hi all, I want to do something like this. A collection, which is not sorted in insertion(added in the next index) and avoid duplicate. Which can I use? Thanks. :)
I appreciate your help all the time... CodingLover :)
It's worth remembering that there isn't a one-size-fits all algorithm to do stuff like this. The framework provides a set of general purpose collections and algorithms, but they might not be good enough in specific scenarios. An unsorted list, which is what I understand you want, is going to be very slow at detecting duplicates. And its going to seriously degrade if you've got lots and lots of things in your collection. It might be worth running two data structures alongside each other to mitigate this. So, roughly how many things are you going to insert into this? Is memory consumption an issue for you? Can we remove duplicates later on, or does it have to be done on insertion?
Regards, Rob Philpott.
-
Hi all, I want to do something like this. A collection, which is not sorted in insertion(added in the next index) and avoid duplicate. Which can I use? Thanks. :)
I appreciate your help all the time... CodingLover :)