Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Array.FindIndex - find index of an element that occurs after some specific element(s)

$
0
0

Hi,

I presume it is better (faster?) to use FindIndex method than to loop through the array using FOR-NEXT?

If so, I would like to know if there is a way to use FindIndex method to find index of an element in array that occurs after some specific element(s). I'm looking for index of an element with value "THE_ONE" like this:

Dim a As Long = Array.FindIndex(myarray, Function(element) element = "THE_ONE")

But "THE_ONE" appears many times in array. I need the one which is preceded by exact 3 elements/values: "VALUE1", "VALUE2", "VALUE3"

So for example:

...

VALUE1

VALUE2

VALUE3

THE_ONE  >>> this is the one I'm looking for

...

...

VALUE12

VALUE56

VALUE22

THE_ONE  >>> this is NOT the one I'm looking for

...

I can get this by using FOR loop and IF statement, but is there a better way?


Viewing all articles
Browse latest Browse all 12583

Trending Articles