3
Answers

Fast Lookup in List

Ask a question
Robert

Robert

16y
6.9k
1
Hi everyone,

i've got a problem using Generic.List. I'm currently writing a program which has to deal with a lot
of data stored in a Generic.List. I often need to search through the list to find out if a new item
is already stored in the list. This is no problem beacause of the Contains-Method. The problem
is this method is very slow and the processing has to be very fast. I've come up with writing an
anonymous function which does the seacrhing for me whcih is way faster. looking like this:

 col = getNewColor();
  if (!colors.Exists(delegate(Color c) { return c == col; }))
{
    colors.Add(col);
 }//
This is also not that fast, concerning what I need for my programm. Is there any way
to speed-up a search through a list?

I appreciate any help.

Greetings LeRoi


Answers (3)