Using Custom Generic Collection is faster with objects than List

I iterate through List<>to find the corresponding element. The problem is that the object has only 2 significant values, Nameand Link(both lines), but has some other values ​​that I do not want to compare.

I am thinking of using something like HashSet(this is exactly what I am looking for - quickly) from .NET 3.5, but the target structure should be 2.0. There is something called Power Collections here: http://powercollections.codeplex.com/ , should I use this?

But maybe there is another way? If not, can you offer me a suitable collection?

+3
source share
2 answers

In .NET 2.0, HashSet<T>you can use instead Dictionary<K, V>.

Dictionaryuses a hash code to perform key searches, so it has a similar action with HashSet. There are at least two approaches:

  • Create your own class or structure containing the name and reference, and use this as a key in the dictionary and put the object as a value.
  • Store the entire object as a key and provide your own comparison mapper, which looks only at the Name and Link element and sets to null.

The second method is very similar to how you would use a HashSet if it was available.

+3
source

How about this:

/, , . int, . , , int , .

?

0

Source: https://habr.com/ru/post/1742723/


All Articles