How to find an item in a List with out itterating trough it

Hi guys,

I’m working on a case with alot of data. At the moment my program has around 1.5milioen itterations.
In order for descrease the time of this program i need to get rid of some clustered loops i have at the moment. One of the most commen once is itterating trough a List to find an item which contains a specific value. Some are List of strings some Integers. But i always work with a for each loop to find it. And it slows my proces down alot.

Any ideas or suggestions how to do this quicker in vb.net?

Kind Regards,
JR

You can use
List.IndexOf(searchValue)

without iterating the list.

Searches for the specified object and returns the zero-based index of the first occurrence within the entire List.

4 Likes

Hmm it return “-1” as the value regardless if the input is in the list or not. Should it be converted into something?

Nvm -1 is the default value as there is nothing pressent in the list. And the returning value is 0 up to … depending on the size of the list. Got it now… Thanks for this really helpfull workaround.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.