Get multiple indexes of a listing

Hello, see if you can help me with this function

I have this list of integers

Hits = {2,4,5,8,2,8}.tolist()

and I have a function that returns the maximum values even if they are 2 or more.

Hits.Where(Function(x) x = Convert.ToInt32(Hits.Max)).ToList ()

return = 8.8

But what I really need is for the function to return the positions of those 2 values to me in the array.

Serian = 3.5

Does anyone know how to modify the function so that it returns the indexes?

Thank you.

@Luis_C
here some options

  • try with an IndexOf (I do feel that it is failing in the 8,8 case)
  • doit it with a for each and return a list of match indexes
  • play with FindIndex method from List and the moved start index
  • indexed search within LINQ statement

I found this

and helped me do the function

Hits.Select(Function(x, i) New With {Key.Index = i, Key.Value = x}).Where(Function(x) x.Value = Convert.ToInt32(Hits.Max)).Select(Function(x) x.Index).toList()

1 Like

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