In a list of integers, Find the index of a cell where the value in it is >600

Moshe Maor 21 Reputation points
2021-03-04T22:56:36.493+00:00

Hello everybody, I have a list of integers. The list is sorted in ascending order. I am looking for a search tool in VB.NET that will return the first index, where the value in list is >600. Of course I can do it with a loop, but I have a feeling that Microsoft thought about it before me. Thanks to all helpers. Moshe.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,714 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 116.6K Reputation points
    2021-03-04T23:08:30.987+00:00

    It offers this possibility:

    Dim numbers As New List(Of Integer) From {100, 330, 610, 610, 700}
    Dim index = numbers.FindIndex(Function(n) n > 600)
    If index >= 0 Then
        ' found
        '...
    End If
    

    The list does not have to be sorted.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.